-
What to do if Salesforce Trigger is not working as expected?
I have a trigger on release(Child of Opportunity) record. The logic for the trigger is in the handler class. I am updating checkbox to true on Opportunity(Parent) whenever release record edited or inserted. The default value for checkbox needs be false and if any record inserted/updated on release object has Release__c.Test__c value starts with other than '14%' then checkbox needs to set to False. I mean to say checkbox will be set to true only when all record has Test__c = '14%' else set to false. I tested my trigger logic but it is not working as expected also with my logic some time I get Maximum CPU error. Any help or suggestion?
trigger updateCheckbocOpp on Release__c (after insert, after update) { list<Release__c> bqList = new list<Release__c>(); for (Release__c childObj : Trigger.new){ listIds.add(childObj.Opportunity__c); } oppsToUpdate = new Map<Id, Opportunity>([SELECT id, Set_Rel__c,(SELECT ID,Test__c FROM Plan_Sum__r) FROM Opportunity WHERE ID IN :listIds]); system.debug('testing trigger >> ' + oppsToUpdate); for (Opportunity opp: oppsToUpdate.values()){ for(Release__c bq :opp.Plan_Sum__r){ system.debug('Release Record >> '+bq); opp.Set_Rel__c = true; if(!bq.Test__c.startsWith('14%')){ opp.Set_Rel__c = false; } } } system.debug('Update >>>' + oppsToUpdate.values()); update oppsToUpdate.values(); }
Log In to reply.
Popular Salesforce Blogs
Provide the right solution | Salesforce & Tableau Integration
Imagine having an advantage that lets you understand your customers better than ever before. That's exactly what happens when you combine the might of Salesforce…
All You Need to Know About Database Class Methods to Perform DML Operations
In this blog, we will discuss Database class methods to perform DML operations. So let's get to the topic. Apex contains the built-in database class.…
Popular Salesforce Videos
What is Apex? | Way to become a Salesforce Developer
Apex is a development platform for building software as a service (SaaS) applications on top of Salesforce's customer relationship management (CRM) functionality. Apex allows developers…
COVID 19 Tracker in Salesforce Lightning Aura Component
In this video, we are developing a lightning Component to track the current pandemic COVID19 Stats Tracker which shows the current situation of all countries…
Non-technical But Want to Build Career in Salesforce?
In this video Shrey gave the answer to the following questions: 1. What is the next step after doing Certification in Salesforce Administrator? 2. How…