-
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
Want to Hire the Best Salesforce Consultants? Here’s Everything You Should Know!
There’s hardly anyone in the business industry who is unaware of Salesforce. We all know Salesforce to be the no. 1 CRM in the world…
Top 5 Accounting Software For Salesforce
Salesforce unlocks the door to opportunities for better customer relationships and engagement. Businesses working on Salesforce might face difficulties in handling income, expenses, cash flow,…
What is an Enhanced Domain in Salesforce in 2023?
Enhanced domains are coming to My Domain in a future version. All URLs within your company—including those for your Experience Cloud sites, Salesforce Sites, Visualforce…
Popular Salesforce Videos
Marc Benioff talks Salesforce - AT&T deal, office health safety and online media regulation
Salesforce’s Customer 360 will enable AT&T to deliver highly-tailored customer experiences seamlessly across retail, marketing, online, business, and more. AT&T will utilize Salesforce’s entire portfolio…
Data Import: Prepare your Data for Import | Salesforce
This short video walks you through how to clean up your import files in preparation for getting your data into Salesforce. We'll walk you through…
Understanding Future Method | Difference Between Asynchronous and Synchronous Apex in Salesforce
In this video, Shrey explained Synchronous Apex and Asynchronous Apex in a simple way. He also explained the importance of the Future method in Salesforce.…