{"id":147,"date":"2013-11-21T08:29:59","date_gmt":"2013-11-21T08:29:59","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/salesforce\/?p=147"},"modified":"2024-08-06T04:26:40","modified_gmt":"2024-08-06T04:26:40","slug":"soql-query-on-combination-of-two-fields","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/11\/21\/soql-query-on-combination-of-two-fields\/","title":{"rendered":"SOQL Query on a combination of two fields"},"content":{"rendered":"<p style=\"text-align: justify;\">Few days back, we had a requirement in one of our projects wherein we needed to list the records based on summation of two fields of an object. We tried to use SOQL query to filter the records, but we found that SOQL query of salesforce natively does not allow the arithmetic operation of two fields in the where clause.<\/p>\n<p>Following is the query which we tried that gave us an error of malformed query &#8211;<\/p>\n<p><b>List&lt;Object&gt; Objs = [Select field1, field2 from Object where (field1+field2)&gt;=25000];<\/b><\/p>\n<p><span style=\"color: #800000;\"><span style=\"color: #000000;\"><em><strong>New<span style=\"color: #000000;\"> Stuff<\/span><\/strong><\/em>:<\/span><\/span><span style=\"color: #000000;\">\u00a0<\/span>\u00a0<a title=\"Excel Export in Salesforce\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/11\/19\/excel-export-in-salesforce\/\" target=\"_blank\" rel=\"noopener\">Excel Export in Salesforce<\/a><\/p>\n<p>We had to look for some workaround to solve this issue, for which we created a new formula field in that object which would be a summation of the two fields.<\/p>\n<p><b>formulafield = field1 + field2<\/b><\/p>\n<p>Now, we can use this newly created field to query on this object to get the \u00a0required records.<\/p>\n<p>New SOQL query will be,<\/p>\n<p><b>List&lt;Object&gt; Objs = [Select field1, field2 from Object where formulafield&gt;=25000];<\/b><\/p>\n<p>Similarly, we also wanted to list the records of the object where field1= field2 which is not supported in salesforce.<\/p>\n<p>For this purpose, we created a new formula field in that object of text type whose formula is as follows.<\/p>\n<p><b>If field1=field2 then newformulafield=\u2019True\u2019<\/b><\/p>\n<p><b>Else newformulafield=\u2019False\u2019<\/b><\/p>\n<p>Then, we used this new formula field in the SOQL query to get all those records from the object whose field1=field2<\/p>\n<p>SOQL query to get the records is as follows &#8211;<\/p>\n<p><b>List&lt;Object&gt; Objs = [Select field1, field2 from Object where newformulafield =\u2019True\u2019];<\/b><\/p>\n<p><span style=\"font-size: Medium;\"><strong>About Us<\/strong><\/span><br \/>\n<a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> as a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners across the globe. We offers Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that requires apex code incorporation into the Salesforce platform.<\/p>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> has some unique solutions for Cloud CRM such as Salesforce integration with <a href=\"https:\/\/www.greytrix.com\/product\/sage-x3\/gumu-x3-salesforce-integration\">Sage Enterprise Management (Sage X3<\/a>), Sage Intacct, <a href=\"https:\/\/www.greytrix.com\/product\/sage-100-erp\/gumu-100-salesforce-integration\">Sage 100, <\/a>and <a href=\"https:\/\/www.greytrix.com\/product\/sage-300-erp\/gumu-300-salesforce-integration\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/product\/crm-development\/salesforce-com\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/data-migration-services\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/integrated-application-development\">Integrated App development<\/a>, <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/custom-development\">Custom App development<\/a> and <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/maintenance-support\">Technical Support<\/a> to business partners and end users.<\/p>\n<p>Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star app listed on <a href=\"https:\/\/appexchange.salesforce.com\/listingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<\/p>\n<p>For more information, please contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n<p><strong><span style=\"font-size: Medium;\">Related Posts<\/span><\/strong><\/p>\n<ul>\n<li><a title=\"PDF Export in Salesforce\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/11\/08\/pdf-export-in-salesforce\/\" target=\"_blank\" rel=\"noopener\">PDF Export in Salesforce\u00a0<\/a><\/li>\n<li><a title=\"Get Key Prefix\/Object id of Object in JavaScript\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/11\/02\/get-key-prefixobject-id-of-object-in-javascript\/\" target=\"_blank\" rel=\"noopener\">Get Key Prefix\/Object id of Object in JavaScript<\/a><\/li>\n<li><a title=\"Mapping custom lead fields to standard contact fields\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/11\/01\/mapping-custom-lead-fields-to-standard-contact-fields\/\" target=\"_blank\" rel=\"noopener\">Mapping custom lead fields to standard contact fields<\/a><\/li>\n<li><a title=\"Overriding standard visual page styling in Salesforce\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/10\/23\/overriding-standard-visual-page-styling-in-salesforce\/\" target=\"_blank\" rel=\"noopener\">Overriding standard visual page styling in Salesforce<\/a><\/li>\n<li><a title=\"Assign custom object permissions to Standard User in Salesforce\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/06\/11\/assign-custom-object-permissions-to-standard-user-in-salesforce\/\" target=\"_blank\" rel=\"noopener\">Assign custom object permissions to Standard User in Salesforce<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Few days back, we had a requirement in one of our projects wherein we needed to list the records based on summation of two fields of an object. We tried to use SOQL query to filter the records, but we found that SOQL query of salesforce natively does not allow the arithmetic operation of two\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/11\/21\/soql-query-on-combination-of-two-fields\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[560,471,473],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-salesforce-soql-query","tag-soql","tag-soql-query"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":3,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":8892,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/147\/revisions\/8892"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}