{"id":1004,"date":"2015-05-14T05:28:04","date_gmt":"2015-05-14T05:28:04","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/salesforce\/?p=1004"},"modified":"2025-06-20T09:06:07","modified_gmt":"2025-06-20T09:06:07","slug":"using-formula-fields-in-triggers","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/05\/14\/using-formula-fields-in-triggers\/","title":{"rendered":"Using Formula Fields in Triggers"},"content":{"rendered":"<p>For one of our projects, we were adding some grouped products in the \u201cOpportunity Products\u201d object through our custom visualforce page.<\/p>\n<p>This seemed a very simple technical implementation. Though it would give us \u2018NULL\u2019 reference error when our custom page would try to insert the product records in the opportunity. However, it worked seamlessly for the standard quote line items page (refer to the screen shot below).<\/p>\n<p><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2015\/05\/1.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-1005\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2015\/05\/1.jpg\" alt=\"1\" width=\"1259\" height=\"477\" \/><\/a><\/p>\n<p>When we dug into the issue we discovered that there was a cutom trigger (before insert) written on the \u201cOpportunity Products\u201d. This trigger was referencing the \u201cList Price\u201d of the product, a formula field based on the Price book entry, which was not available in the before insert operation. Therefore, every logic written on the basis of this field would fail.<\/p>\n<p>This issue can be easily resolved, all one needs to do is, query all the values for formula fields for the records to be inserted before you start processing the records in the trigger.<\/p>\n<p>Happy Coding !!<\/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=\"Experience Salesforce1 on desktop\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/03\/29\/experience-salesforce1-on-desktop\/\" target=\"_blank\" rel=\"noopener\">Experience Salesforce1 on desktop<\/a><\/li>\n<li><a title=\"Salesforce Data Export Service\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/03\/27\/salesforce-data-export-service\/\" target=\"_blank\" rel=\"noopener\">Salesforce Data Export Service\u00a0<\/a><\/li>\n<li><a title=\"Clone records directly by editing record URL\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/03\/26\/clone-records-directly-by-editing-record-url\/\" target=\"_blank\" rel=\"noopener\">Clone records directly by editing record URL<\/a><\/li>\n<li><a title=\"Mass Email Salesforce Users\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/02\/28\/mass-email-salesforce-users\/\" target=\"_blank\" rel=\"noopener\">Mass Email Salesforce Users<\/a><\/li>\n<li><a title=\"Trailhead \u2013 A new way to learn Salesforce\" href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/02\/28\/trailhead-a-new-way-to-learn-salesforce\/\" target=\"_blank\" rel=\"noopener\">Trailhead \u2013 A new way to learn Salesforce<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>For one of our projects, we were adding some grouped products in the \u201cOpportunity Products\u201d object through our custom visualforce page. This seemed a very simple technical implementation. Though it would give us \u2018NULL\u2019 reference error when our custom page would try to insert the product records in the opportunity. However, it worked seamlessly for\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/05\/14\/using-formula-fields-in-triggers\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[137,247,248,501],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-formula-field","tag-opportunity","tag-opportunity-products","tag-trigger"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/1004","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=1004"}],"version-history":[{"count":4,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":10988,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/1004\/revisions\/10988"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}