+ Start a Discussion
vikramkkvikramkk 

Data from Parent object in to Child object

Hi

 

I have a custom object with look up to Opportunity. I want some of opportunity field values to be copied in to this custom object fields at the time of first saving the custom object record. How can I achieve this?

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma

Welcome dude, can you please mark it as resolved?

All Answers

Bhawani SharmaBhawani Sharma

You can use before insert event.

You can query all the fields from the opportunity in the trigger using the relationship field .

like if you have Opportunity__c field on the Custom object then yo can do :

 

List<Opportunity> listOpp = [Select id, Name from Opportunity where Id = Trigger.new[0].Opportunity__c];

 

and then

Trigger.new[0].Name =  listOpp[0].Name;

 

 

 

vikramkkvikramkk

It worked. Thanks a lot.

Bhawani SharmaBhawani Sharma

Welcome dude, can you please mark it as resolved?

This was selected as the best answer