You need to sign in to do that
Don't have an account?
Admin User 10568
Next Start Date Using Business Hours
Hi, I would like to create a trigger that prints the next business date/time available to a custom field on a custom object. I would like the trigger to run after each new instance of the object type. I'm getting an error "a value cannot be stored to Task_Start_Time__c in type Repro_Lead__c". It's a datetime field and I was wondering how I could get this to work?
trigger NextAvailableBusinessMoment on REPRO__Lead__c (after insert) { // Get the default business hours BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true]; // Starting from the System.now, find the next date when business hours reopens. // This returned next day start time will be in the local time zone Datetime nextStart = BusinessHours.nextStartDate(bh.id, System.now()); // print nextStart date/time in custom field on trigger object REPRO__Lead__c.Task_Start_Time__c = nextStart; }
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
All Answers
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
A little mistake from your side:
As per salesforce best practice we need to use bulkify so what we need to do just below:-
for(REPRO__Lead__c repo_lead : trigger.new)
{
repo_lead.Task_Start_Time__c = nextStart;
}
So please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh