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
hylim1215hylim1215 

How to execute triggers from class

is it possible to execute triggers from class? Let's say i want these triggers to execute at 12am everynight. is there a way to do this?

HariDineshHariDinesh

Yes, you can execute trigger from Apex Class.

 

Her you want to run trigger on specific time. So you need to scheduler.

 

For this write a class which implements a scheduler interface and write code such that any insert or update operation on particular object on which you have written a trigger.

 

Now go to Apex Class link and click on Schedule Apex button and select the class you have implements the scheduler and schedule it as you required.

 

Here is an example for scheduler class


Global with sharing class ScheduleClassname implements Schedulable {
   Global void execute (SchedulableContext SC)
      {
        // Required Logic to fire trigget
     }
 
      }

 

 

 

hylim1215hylim1215

ok, let's say i import accounts and contacts into SFDC. for instance, for address field, i have another custom field that copy from all the standard address field values. i can loop it. however, there is limitation to the loop, right? i hit limitation issues while looping till 5k records previously. how can i avoid such issue? say i have 10k accounts and i want to loop through each of them. any way to do so? thanks

HariDineshHariDinesh

Hi,

 

I didn't understand clearly what you are looking for. 

 

But If you have more number or records use Batch Apex to avoid this and make batch size as per you required.

 

hylim1215hylim1215
Hi,

ok. i have 1 trigger that copies all address standard field into a custom field when account is created/updated.

however, if i import the account - meaning the account is not created/updated, the trigger will not fire.

so, i would like to write a class that can execute the trigger by scheduling it to run at 12am each day.

is this possible?

another issue is, whenever i loop through account sets, whenever it hits 5k records, i get the over limit issue. so in the above case, i will need to loop through. it will throw the same error. is there a way to avoid it?