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
Ravi varma PenmethsaRavi varma Penmethsa 

Invoke a autolaunched flow from a "Before Update" trigger on a work order

Hi All,
Hope everyone taking care of you and your family during this covid-19 Pandemic. 

To start with, I am newbie in saleforce and just started my journey a month ago. Trying out some POC and struck. Looking for some advise.

Requirement: When a work order status is changed. For example: From New to Inprogress. I want to invoke a autolaunced flow which updates work order object properties like enddate, priority etc.

I have done some lookup in documentation and tried below approach.
1. Create a Autolaunched flow on work order object based on conditions and able to update the required properties as needed above.
2. Able to call this flow from a Process defined in Process builder. Process builder was helpful in case of Status changed to Inprogress(After the record got changed).It also does not check previous status value or status transition. It works until I final status value is Inprogress. 

But i want to verify while the change is happening (before update)and in addition only if the status changed from New to inprogress. 

3. Explored few other options, In Object manager->Work order. found triggers.
Thought, I would create a APEX calss for Before Update on workorder and call autolaunced flow within APEX class if condition of previous status= NEW and Updated status value=In progress value.

So here are the queries from my end;
1. Am I taking a long path, is there simple and OOTB functionality I can acheive this without writing APEX class.
2. If need to write APEX class or action to acheive this functionality, is my above mentioned approach correct.
3. How can I read previous value of field and the new updated field value in before event of trigger?

Thanks,
Ravi
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ravi,

To my knowledge I think you would be needing a custom solution for your implementation and have you considered using  PRIORVALUE in the process builder as described in the below link.

>> https://help.salesforce.com/articleView?err=1&id=customize_functions_i_z.htm&type=0

And in case if you want to implement it using trigger you would be able to access the old values using trigger.old in which you will have access to that old read only values .

>> regarding the trigger.old and other context variables please follow this link - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables_considerations.htm?search_text=trigger.old

In case if the above description was helpful in your query can you please close the thread by marking this as the best answer so that it can be used by others in the future and also it helps in keeping our community clean.

Regards,
Anutej.