Our company has been refactoring flows lately due to Apex timeouts, and we're trying to decide which method runs more efficiently.
Previously, we would get a Get element to assign values of a parent record to variables; however, it appears we can also create variables on their own and then define the value of a parent record's fields as the Default Value.
Ex. {!$Record.Parent_Record__r.Value}
My question is, on the backend, is it performing a DML for each of those variables if I set the value using the example above? Which method is more efficient, and which is best practice?
My question is, on the backend, is it performing a DML for each of those variables if I set the value using the example above?
For my test, I did the following setup. I don't know if it matches your situation but thought it would work.
Project__c
--- Project_Item__c (Child object connected via master-detail)
Both objects have Dummy__c (Text: 255) field. I wrote my use-case to copy down the field value from the parent on upsert.
I think wrote two record trigger flows. BEFORE context (Fast Field Updates)
Scenario 1:
Scenario 2:
I opened up the developer console. Set my debug level to Finest. I performed an update call on the child object with each scenario while the other flow was deactivated.
Findings:
Scenario 1:
Scanerio 2:
Which method is more efficient, and which is best practice?
That is a little subjective here to personal taste. I prefer my flows to have the fewest nodes possible but still be easy to read. In this case, if efficiency is more the best practice, definitely go the assignment via lookup route. I generally do it that way anyways without thinking about it. Its usually easier too.