You need to sign in to do that
Don't have an account?
minimize the no of script statements
hey all,
Here's a simple trigger.
There are 2 for loops and a soql query to loop through.
comparing the WBS2 values, I update the WBS2 order from WBS_2_Order__c object to SPM object.
how can I refine it to reduce the no of script statements/no of soql queries? Using maps? (any samples)
trigger SPMUpdateWBS2Order on Site_Progress_Monitoring__c (before insert,before update) { List<WBS_2_Order__c> wbs2OrderList = [Select Id,Name,WBS_2__c,WBS_2_Order__c FROM WBS_2_Order__c]; for(Site_Progress_Monitoring__c spm: trigger.new){ for(WBS_2_Order__c wb2Order: wbs2OrderList){ if(spm.WBS_2__c == wb2Order.WBS_2__c) spm.WBS_2_Order__c = wb2Order.WBS_2_Order__c; } } }
Cheers!
Using map for this won't make any change in the number of scrip statements.
The only way to reduce number of script statements is to reduce the looping of the inner FOR loop,
For that you need to restrict the query results.
Try using WHERE clause if you have some condition to meet.
Regards,
Rohit R
Hi Manish,
Try this...
I got the below error
Aren't WBS_2_Order__c and SPM related via lookup?
How to reduce the no of soql queries in this another simple trigger?
Please help!
Thanks much.