You need to sign in to do that
Don't have an account?
Aldrino Rodrigues 3
Scheduled Apex Trigger - to Auto update Custom Field Values if Conditions are met.
Hi,
Please can someone help with with an Apex scheduled trigger or guide me in the right direction.
I have the below custom fields in Salesforce :
Date field >> 'Renewal date'
Pick list >> 'Account Type'
Pick list >> 'Contract Type'
Text Field >> 'Product 1 Delivered'
Text Field >> 'Product 2 Delviered'
The Trigger is to run daily
I've tried to explain the query logic as best as i can below.
IF
Renewal date = Today
AND
Contact Type = "Auto-Renew"
AND
( Account Type = 'Active Client' - OR - 'On-Hold Client' )
THEN,
UPDATE 'Product 1 Delivered' = 0,
UPDATE 'Product 1 Delivered' = 0,
UPDATE Renewal date = Renewal date + 365. i.e next year
I'd also love if there was a way to send out an email alert or chatter post; however this is secondary.
I hope this make sense.....
I dont know enough APEX to do this yet. Any help will be highly appriciated.
Thank you
Please can someone help with with an Apex scheduled trigger or guide me in the right direction.
I have the below custom fields in Salesforce :
Date field >> 'Renewal date'
Pick list >> 'Account Type'
Pick list >> 'Contract Type'
Text Field >> 'Product 1 Delivered'
Text Field >> 'Product 2 Delviered'
The Trigger is to run daily
I've tried to explain the query logic as best as i can below.
IF
Renewal date = Today
AND
Contact Type = "Auto-Renew"
AND
( Account Type = 'Active Client' - OR - 'On-Hold Client' )
THEN,
UPDATE 'Product 1 Delivered' = 0,
UPDATE 'Product 1 Delivered' = 0,
UPDATE Renewal date = Renewal date + 365. i.e next year
I'd also love if there was a way to send out an email alert or chatter post; however this is secondary.
I hope this make sense.....
I dont know enough APEX to do this yet. Any help will be highly appriciated.
Thank you
Following is the code,
Batch Class:
Scheduled class:
Currently, the Batch class has dummy field names so you will have to change those with your actual field and object names.
Scheduled Class: I prefer storing the schedule(when to run the batch job) in a custom label so we can change the schedule without requiring us to change the code. so will need to create a new custom label with Name: AutoRenewSchedule and Value: 0 0 6 ? * * it is set to run at 6 am everyday.
then execute in Developer Console >> execute anonymus
autoRenewScheduler.SchedulerMethod('Daily Auto-Renewal');
Hope this helps, Good Luck!