Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to copy field data from one object to another with a click on a button. I want to get a snapshot of the current family status and copy the data from related son and father data.

I have an custom object son with the following fields: s_name, s_street and father, where father is a lookup to object father, which has the fields f_name and f_age.

I want to have a button on the son page, saying new family, which populates another custom object family with the respective fields from the originating objects: s_name, s_street etc.

How would I realize such a copy action via Apex?

share|improve this question
You'll likely need to write some Apex code backing the button to handle this action, as it isn't out of the box. – Michael Welburn Dec 12 '12 at 18:50

If you want on a button call go for custom button with apex behind it doing job of creation and populating the data.

If you want that as soon as a new Son record and automatic family record is created and populated go for trigger,

//apex method pseudo code

public pagerefrence createfamilyrecord(){

 Id recordId = System.currentPagereference().getParameters().get('Id');

 List<Son__c> lstson=[Select Id ,s_name, s_street from Son__c where id =:recordId];


   Family__c fam=new Family__c();



    insert faml;

    return null;//Return where you want the navigation to be 


//Visualforce pseudo code

<apex:commandButton action="{!createfamilyrecord}" value="NEw Family" id="theButton"/>
share|improve this answer
It's supposed to be on a button click, not on a new son record. Do you have any link on the Apex code? – mcbetz Dec 12 '12 at 18:53
I got the question more concise, and sorry, your answer does not solve the problem yet. – mcbetz Dec 12 '12 at 19:06
updated the answer!Hope that helps you – Mohith Shrivastava Dec 12 '12 at 19:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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