This is loosely related to a recent question: Standard Button CODE Available?

Does anyone know of any examples/tutorials on creating a custom button which will set values into the PARENT record of the record/object that the button is clicked from?

Example: Opportunity has a Custom Object called Company Form. When Credit Card data is submitted via a Company Form and approved by various parties, they'd like a button to copy the CCard data into similarly named fields on the Parent (Opportunity).

So CreditCard_Name__c would be copied to the Opportunity's CCard_Name__c field as an example.

2 Answers 2


You can use a custom JS button and it would look something like this-


var connection = sforce.connection;

var oppty = "{!Company_forms__c.OpportunityId__c}";

if (oppty  != "")
    var opp = new sforce.SObject("Opportunity");
    opp.Id = oppty ;
    opp.CCard_Name__c = "{!Company_forms__c.CreditCard_Name__c}";

    alert("There is no Opportunity to update.");

Here is a good reference: http://www.salesforce.com/us/developer/docs/ajax/Content/sforce_api_ajax_more_samples.htm


Is there really a need for a button? You could accomplish this with workflow:

  1. Create a WF with rule, Company Form -> Status = "Approved"
  2. Create Field Updates with Cross Object WF that would copy these values from the Company Form to the Account

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .