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
Christian Kendall 10Christian Kendall 10 

How to write Apex code for Lead Create Date + 15 Minutes

Hello Salesforce Community - First post #1!

Business Goal : 15 minutes after a lead is created from a web-to-lead form I'd like to reassign the lead to a queue if the SDR has not updated the lead status from default value of "Not Started".

Problem :  Process builder doesn't allow you to use conditions based on custom formula fields which would display the created time and compare to the time now.

Solution : Write Apex code, have that code populate a field on the lead object indicating the created date/time + 15 minutes. Then process builder can evaluate the created date time to see if Now () created date is greater than the created date + 15 minutes.  This would allow for the conditions to be met and the record owner updated to the queue.  

Can someone please help me write this code and understand how to push it to the field on the lead object which is not going to be a formula.
Mahesh DMahesh D
Hi Christian,

Please use the below trigger on Lead object:

Created a custom Date Time field on Lead object and added the below trigger.
trigger LeadTriggerForCD on Lead (before insert) {
    for(Lead l: Trigger.new) {
        l.Custom_Created_Date__c = System.now().addMinutes(15);   
    }
}

I also tested the above code in my DE environment and it is working fine.

Please do let me know if it helps you.

Regards,
Mahesh
Christian Kendall 10Christian Kendall 10
Hi Mahesh! Thanks for the help.  On the lead object with force.com I don't have the option to add a new trigger. I am a system administrator in salesforce.

How do I enable triggers to be added?

No add trigger button
Mahesh DMahesh D
Hi Christian,

Which edition you are using in PA you can't write the Apex Code.

Regards,
Mahesh
Christian Kendall 10Christian Kendall 10
Hi Mahesh,

Do you mean to say that the Salesforce edition we have "PA" doesn't allow for us to add Apex code?  Are there any work arounds?

-Christian