-
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
Should You Do Salesforce Backup — All You Need To Know
If you ever lost your data, you know how devastating it is. But what if this data affects the entire enterprise's functioning? Dealing with sensitive…
Testing HTTP Callouts using SFCraft MockServer: Part 1 | Salesforce Help Guide
Recently I published my MockServer lib. The history behind it is simple — for years I’ve been writing HttpCalloutMock implementations for each new project. I don’t want…
How to Stop a Journey in Salesforce Marketing Cloud
It was time-consuming to pause Salesforce Marketing Cloud's progress. It will provide you with tips to help you save money while still achieving them. Marketing…
Popular Salesforce Videos
Flow to Redirect User to Newly Created Record - Salesforce Flow
Scenario: Shubham is looking for functionality in Salesforce Flow Where after creating a record it redirects to that particular record detail page. Solution A: Create…
Introduction to Salesforce Commerce Cloud for Developers
Commerce Cloud powers e-commerce for many of the world's leading brands and it represents a great opportunity for developers around the world. Join us to…
AppExchange Demo Jam - April 2020
Watch AppExchange apps Lifeguard Solutions, FilePulse, Vonage, Icertis, Taskray, and Salesforce Crisis App from Salesforce Labs demo their technology in three minutes for the audience…