You need to sign in to do that
Don't have an account?
Sonam Patil
Trigger to insert in one object and get updated in other object
Hi,
I am new to SFDC development.
Can anyone explain to me how to write a trigger, if we inserting data in one object and should get updated in another object.
I am new to SFDC development.
Can anyone explain to me how to write a trigger, if we inserting data in one object and should get updated in another object.
Map is key value pare with account id we can get account record
let us know if this will help you
All Answers
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000kBYfIAM
which is helpful
Please check the below sample code.For example, I want to create a record in Account object automatically created a record in contact object.
Hope this helps you!
Regards,
Jyothsna
I will suggest you please check trailhead to learn about trigger. I hope that will help you
1) https://developer.salesforce.com/trailhead/module/apex_triggers
Sample code Let us know if this will help you
Thanks
Amit Chaudhary
Thank you for the quick response.
Can you explain me the below code in detail.
And why set, why not List.
And why Map
trigger ContactTrigger on Contact (before insert, before update) {
Set<Id> accIds = new Set<Id>(); for(Contact con : trigger.new) {
accIds.add(con.AccountId);
}
Map<Id,Account> accountMap = new Map<Id,Account>( [select Phone from Account where id in: accIds] );
for(Contact con : trigger.new) {
con.phone = accountMap.get(con.accountId).Phone;
}
}
Map is key value pare with account id we can get account record
let us know if this will help you