You need to sign in to do that
Don't have an account?
Rahul Luthra 1
Flow to populate latest related record
Hello, Kindly help me to understand how can we achieve the below scenario via flow?
I have a custom object DD which is currently associated with the account object using Master-Detail Relationship where we can have multiple DD's against each account.
Now, when a user creates a new opportunity and associates it to the account (using lookup), DD's data like date and status should be auto-populated on the opportunity custom fields from the latest DD's record created.
TIA
I have a custom object DD which is currently associated with the account object using Master-Detail Relationship where we can have multiple DD's against each account.
Now, when a user creates a new opportunity and associates it to the account (using lookup), DD's data like date and status should be auto-populated on the opportunity custom fields from the latest DD's record created.
TIA
Map<Id, Account> accountMap = new Map<Id, Account>();
for (Opportunity opp : Trigger.new) {
if (opp.AccountId != null) {
accountMap.put(opp.AccountId, null);
}
}
if (accountMap.keySet().size() > 0) {
accountMap.putAll([SELECT Id, (SELECT Id, Date__c, Status__c FROM DDs__r ORDER BY CreatedDate DESC LIMIT 1) FROM Account WHERE Id IN :accountMap.keySet()]);
}
for (Opportunity opp : Trigger.new) {
if (opp.AccountId != null) {
Account account = accountMap.get(opp.AccountId);
if (account != null && account.DDs__r.size() > 0) {
DD__c latestDD = account.DDs__r[0];
opp.Date__c = latestDD.Date__c;
opp.Status__c = latestDD.Status__c;
}
}
}
}
As per your scenario , I would request you to go through these Help video and articles .
-> https://www.youtube.com/watch?v=_V4TklKOoPc
--> (https://help.salesforce.com/s/articleView?language=en_US&id=sf.flow_build_data_update.htm&type=5)
--> https://developer.salesforce.com/forums/?id=906F0000000As9xIAC
--> (https://help.salesforce.com/s/articleView?id=release-notes.rn_automate_flow_builder_update_related_records.htm&release=240&type=5)
Hope the above information helps !
Thank you.
You can follow the below steps to create Flow :
1. Start the flow when a new opportunity is created and associated with an account.
2. Use a 'Get Records' element to retrieve the related DD records for the associated account. In the element, set the following:
3. Use a 'Get Records' element to retrieve the latest DD record from the previous step. In the element, set the following:
4. Use a 'Record Update' element to populate the custom fields on the opportunity record with the values from the latest DD record. In the element, set the following:
5. Save and activate the flow.
Hope this will help.
Thanks!