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
jutamindjutamind 

Call a trigger from scheduled job

Hi,

I have a trigger in the Account object that does field updates on multiple updates. We didnt use workflow rules since it's too limited for our needs.

I would like to run/call this trigger once a day. How do i do this? Do i need some codes to schedule a job to call this trigger in Account object?

PS: I'm no developer. :(

Navatar_DbSupNavatar_DbSup

Hi,

 

If you need to run your trigger on daily basis then for this you will have to fire some event like insert, update or delete from a schedulable class. For example

 

== This a Trigger on Account=======

 

trigger TestScheduledTrigger on Account (after update) {

system.debug('___________Trigger Works________________');

for(Account a:Trigger.new)

{

system.debug('__________Test acc________'+a);

}

 

}

 

 

Now you can run This Trigger by doing update event in Scheduler class. Below is a code for Scheduler class for reference

 

global class RunTrigger implements Schedulable

{

 

global void execute(SchedulableContext ctx)

{

    system.debug('____________scheduled test________________');

    List<Account> a=[select id from account Limit 1];

        system.debug('______Controller____'+a);

        update a;

}

      

}

 

Now you just need to schedule the above class on daily basis.  For more details follow the  below  link.

 

http://boards.developerforce.com/t5/General-Development/Call-a-trigger-from-scheduled-job/td-p/442135

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.