0

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

  • 4
    why 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 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
1

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.