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
Parikshit Sarkar 14Parikshit Sarkar 14 

Can someone explain me what should be the answer? Thanks.

A custom field Exec_Count_c of type Number is created on an Account object. An account record with value of "1" for a: Exec_Count_c is saved.

A workflow field update is defined on the Exec_Count_c field, to increment its value every time an account record is created or updated. The following trigger is defined on the account:

trigger ExecOrderTrigger on Account (before insert, before update, after insert, after update){ for (Account accountInstance: Trigger.New){ if (Trigger . isBefore) { accountInstance Exec_Count_c += 1; } System. debug (accountInstance.Exec_Count_c); } }
Best Answer chosen by Parikshit Sarkar 14
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Parikshit,

In the above scenerio if the Exec_Count_c value is zero while inserting. So after the record is saved to database it will be 3. For each update the count will be incremented by 3.
One increment for before update/insert.
second increment for workflow update
third increment will again come for trigger.

Please find the ordedr of excution for more information.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Parikshit,

Can you please let the community what is needed. You have a workflow and trigger. Do you need which one to use?

Thanks,
Parikshit Sarkar 14Parikshit Sarkar 14
Hi praveen, 

I encountered a situation where both are in use. I need to know what should be the output in this case. 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Parikshit,

In the above scenerio if the Exec_Count_c value is zero while inserting. So after the record is saved to database it will be 3. For each update the count will be incremented by 3.
One increment for before update/insert.
second increment for workflow update
third increment will again come for trigger.

Please find the ordedr of excution for more information.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
VICKY_SFDCVICKY_SFDC
Hi Parikshit,

Exec_Count_c initial value is 0 and once record save to Database it will be 3 and increase by 3 after every count.
1st  increment for before update/insert(UPSERT).
2ND  INCREAMENT USING WORKFLOW UPDATE.
3RD BY TRIGGER.


FOLLOW ORDER OF EXECTION (BELOW LINK):

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

IF MY ANSWER HELP YOU MARK IT AS BEST ANSWER.


THANKS