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
Ankit Garg 117Ankit Garg 117 

Trigger to perform Multiple workflows

Hey..

I have 4-5 workflows which do the same function on the Account object. They all put a Date Stamp based on different fileds in a picklist. Since we have 5 options in a picklist and we are tracking the date of every option, I have to create 5 different workflows. 

I have little to no experience working with Triggers. Is it possible to achieve this with 1 trigger?


Thanks 
Best Answer chosen by Ankit Garg 117
Andrew GAndrew G
Yes you could do this with a Trigger.

But why not consider a Process Builder?  I assume you have 5 x date fields that relate to each status.
Do one Decision point based on the Picklist changing.Then do 1 x IA where you have formula to update each of the Date Fields, using formula which tests the Status field and then updates the associated Date field.  Psuedo code : NewStatusDateField = formula IF(ISCHANGED(Status) && ISPICKVAL(Status,"New"), NOW, NewStatusDateField)

Regards
Andrew

All Answers

Andrew GAndrew G
Yes you could do this with a Trigger.

But why not consider a Process Builder?  I assume you have 5 x date fields that relate to each status.
Do one Decision point based on the Picklist changing.Then do 1 x IA where you have formula to update each of the Date Fields, using formula which tests the Status field and then updates the associated Date field.  Psuedo code : NewStatusDateField = formula IF(ISCHANGED(Status) && ISPICKVAL(Status,"New"), NOW, NewStatusDateField)

Regards
Andrew
This was selected as the best answer
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ankit,

I believe your use case is that according to the type selected from the picklist you are inserting the record with the selected values and timestamp.

If that is the case you can implement the scenario using a single trigger on account object by checking the picklist value and appending the appropriate text to the account name before inserting or updating.

Of course this may vary according to your business case.

Kindly let me know if this helps and please close the thread marking a best answer and also mark a best answer so that it would be helpful in the future for others and it would help us keep the community clean.

Regards,
Anutej Poddaturi

 
Ankit Garg 117Ankit Garg 117
Hey Andrew,

Totally agree. I should use process builder. This will keep the implementation easy and non complicated. 

Thanks for Psuedo code.

Cheers
Ankit Garg 117Ankit Garg 117
Hey Andrew/Anutej

I am tryifng to do this via Process Builder but seems to be stuck. 

So I have a filed (Picklist Type) called ''Practice Stage''. I have another filed (Date Type) called ''Practice Stage Cold Date''. 

What I am trying to achieve is if ''Practice Stage'' is "Cold", ''Practice Stage Cold Date'' will automatically gets updated with todays date. Similarly, if ''Practice Stage" is "Demo Booked'', ''Practice Stage Demo Booked Date'' should automatically be updated with Todays date.

Here is what I am trying under the formula on process builder.

IF(ISCHANGED([Account].Practice_Stage__c ) && ISPICKVAL(Cold), NOW, [Account].Practice_Stage_Cold_Date__c )

Surely i'm not doing this correctly. 
Andrew GAndrew G
Note that ISPICKVAL compares a field to a string, so two 'components' are required in the formula e.g. ISPICKVAL(Practice_Stage__c,"Cold")
Additionally, the formula NOW (or more correctly NOW() ) , returns a DateTime Value which is incompatible with a Date Type field. Where as TODAY() will return a Date value.
I have also found that sometimes the AND nomemclature works better than the &&.  (Similarly OR versus ||)
in your case, try the code as :
IF(
    ISCHANGED([Account].Practice_Stage__c )  && 
    ISPICKVAL([Account].Practice_Stage__c,"Cold") , 
  TODAY(), 
  [Account].Practice_Stage_Cold_Date__c 
)
or alternately:
IF(
  AND(
    ISCHANGED([Account].Practice_Stage__c ) , 
    ISPICKVAL([Account].Practice_Stage__c,"Cold"
  ), 
  TODAY(), 
  [Account].Practice_Stage_Cold_Date__c 
)

Regards
Andrew
Ankit Garg 117Ankit Garg 117
Thanks Andrew for the insights and it helped too.