function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Iswarya SekarIswarya Sekar 

call a trigger from anonymous

Hello guys,

I have a requirement like if the candidate is also a lead, then in leads i have to insert a flag field. this i have done for the records which were inserting newly.

now for the existing records i have to update the field value with a flag. for that i have to run my trigger in anonymous window.
may i know how should i call trigger in anonymous window
GovindarajGovindaraj
Hi Iswarya,

We cannot call a trigger directly, we need to perform the action (say insert, update etc.) in 'Anonymous window'.
 
List<Lead> lstLead = [SELECT FirstName FROM Lead];
List<Lead> lstUpdateLead = new List<Lead>();
for(Lead leadObj : lstLead) {
  leadObj.FirstName = 'Something';
  lstUpdateLead.add(leadObj);
}
Update lstUpdateLead;

Thanks,
Govindaraj.S
GovindarajGovindaraj
Hi Iswarya, 
Please keep this community clean by closing the solved cases.