You need to sign in to do that
Don't have an account?
mb_
APEX Bulk Lead Update
Hey guys,
I am kinda new to APEX triggers and I try to solve the following challange:
I built a trigger which updates 2 fields (integer field and picklist field) depending on 2 other picklist fields. Behind those updated fields are some values like:
After I changed those values in the first trigger I want to update all leads (something about 2000) with another trigger. Best way would be to press a button within the lead record view.
Do i need to save all leads to a list via a query first to update them after via "update leadList"? Or what would be the best way to get this problem solved?
Thanks!
Best
I am kinda new to APEX triggers and I try to solve the following challange:
I built a trigger which updates 2 fields (integer field and picklist field) depending on 2 other picklist fields. Behind those updated fields are some values like:
if(ScoreAbs <= 21){ a.ScoreTotal__c = 'Bronze'; }else if(ScoreAbs > 21 && ScoreAbs <= 28){ a.ScoreTotal__c = 'Silver'; }else if(ScoreAbs > 28 && ScoreAbs <= 33){ a.ScoreTotal__c = 'Gold'; }else if(ScoreAbs > 33){ a.ScoreTotal__c = 'Platinum'; }"ScoreAbs" is calculated via another method. That trigger works fine and there are no errors in it. Now I need to change values within the above code, e.g. values like 21, 33, 28 etc...
After I changed those values in the first trigger I want to update all leads (something about 2000) with another trigger. Best way would be to press a button within the lead record view.
Do i need to save all leads to a list via a query first to update them after via "update leadList"? Or what would be the best way to get this problem solved?
Thanks!
Best
Stroing them in a list and doing a bulk update also works fine.
But implementing the logic to update in a Apex class, gives us flexibility to control the order of logic execution. First the scoreAbs logic and then another batch apex class which will update the Lead.
Also, if there's a possibility that the trigger update will call this trigger again, it will result in a loop. So you can use static variable to control the trigger re-entry.
Let's wait to hear it from the experts too..
Thanks
What trigger does not work is that one which just updates all leads once... manual process would be to just press edit and save again, so that the trigger fires, but for over 2500 leads it would take a time so do that...
"first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00Q3E000002IpDX) is currently in trigger UpdateLeadTrigger, therefore it cannot recursively update itself: []: Trigger.UpdateLeadTrigger: line 8, column 1"
Sorry If I am not clear. I meant to remove the last update statement. The above code should defnitley work.
SELECT Id, updated__c FROM Lead where Id IN Trigger.New