I m new to salesforce.i have custom object Lease__c , i wanna update the account name and owner field from opportunity.In lease__c i have lookup for opportunity field.how to write trigger for Lease__c for after insert
-
4why would you want to go with a trigger for this. You could achieve this using formula or a workflow field update. – Shailesh Deshpande Feb 11 '16 at 12:23
-
Hi Harini, Welcome to SFSE. you can refer this Trailhead module to get started with triggers developer.salesforce.com/trailhead/module/apex_triggers and if you got stuck after trying on your own, you can post with details on where you need help further. – Vamsi Krishna Gosu Feb 11 '16 at 12:24
-
@ShaileshDeshpande is right, use triggers for complicated stuff like batch processes, or multi-object decision trees. Try to create workflow, which updates fields after record creation. – Martin.Kona Feb 11 '16 at 13:27
On custom object Lease__c
, create two new formula fields. These are called cross-object formula fields.
Account_Name__c with formula expression = opportunity__r.account.name
Opportunity_Owner__c with formula expression = opportunity__r.owner.name
If the Lease's opportunity owner changes, any reports or views on that Lease object will automatically pick up the new owner name; same if the Lease's Opportunity's Account name changes (or even if the Opportunity is switched to a different Account).