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
John C..ax1662John C..ax1662 

Update a field with today's date based on a certain value being selected in another field

Hi, I have 2 fields in accounts - the first is "Lead Status" and the second is "Date Qualified". For tracking purposes. I would like today's date to be automatically populated in the "Date Qualified" field based on when "Qualified" is chosen in the "Lead Status" field.

 

I'd also like to make the "Date Qualified" field not able to be edited unless you are an admin.

 

Any help would be greatly appreciated.

 

Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
:) :) :) :) :):) :) :) :) :)

No need for trigger here. Workflow is more easier to edit later if any changes occurred.

 

Create workflow from Your Name  --> Setup --> create --> workflow & Approvals --> workflow rules.

 

1) Select Lead object

2) Give rule name your Evaluation criteria would be "created, and any time it’s edited to subsequently meet criteria" as per your requirement. 

3) Rule Criteria Lead: Lead Status equals Qualified click save and next

4) Select workflow action new field update 

5) Give name, Description select Date Qualified field to update.

6) Select "Use a formula to set the new value" and Put function Today() if your field type is Date or Now() if your field type is Date/Time.

7) Done

8) Active your workflow (Don't miss this step)

 

Thanks!

 

All Answers

Vinit_KumarVinit_Kumar

John,

 

1.) for first part where you want to populate "Date Qualified" with today's date you can create an Apex Trigger(before insert,before update Trigger on Lead).Infact a workflow would also work.

 

2.) for the 2nd part,you can create a Validation rule where noone is able to edit the field except Admin.

John C..ax1662John C..ax1662

Hi Vinit,

 

Any chance you could provide me with the actual code for this?

Vinit_KumarVinit_Kumar

Hi John,

 

Try below code for the Trigger :-

 

Trigger updateDate on Lead(before insert,before update){

for(Lead le:Trigger.new){
if(le.status=='Qualified'){
le.Date_Qualified__c=system.today();
}

}
}

:) :) :) :) :):) :) :) :) :)

No need for trigger here. Workflow is more easier to edit later if any changes occurred.

 

Create workflow from Your Name  --> Setup --> create --> workflow & Approvals --> workflow rules.

 

1) Select Lead object

2) Give rule name your Evaluation criteria would be "created, and any time it’s edited to subsequently meet criteria" as per your requirement. 

3) Rule Criteria Lead: Lead Status equals Qualified click save and next

4) Select workflow action new field update 

5) Give name, Description select Date Qualified field to update.

6) Select "Use a formula to set the new value" and Put function Today() if your field type is Date or Now() if your field type is Date/Time.

7) Done

8) Active your workflow (Don't miss this step)

 

Thanks!

 

This was selected as the best answer
John C..ax1662John C..ax1662

Thanks Ketan. That worked exactly as I wanted it to. Now just need to make the field only editable by admins and I'm set but I think I know how to do that. Thanks.

:) :) :) :) :):) :) :) :) :)

For access control you can use

1) Validaton rule. 

           (OR)

2) Make it read only through page layout (very easy)

John C..ax1662John C..ax1662

Thanks Ketan got it all set up.

Arpit Gupta 62Arpit Gupta 62
When Lead Status Set to 'Working - Contacted ' send email to Client i.e . Lead's Email 
    And add Date to field ‘Date_to_Send_email__c’  i.e today's date.