Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

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 have custom button on Opportunity.On click of button I need to pre populate values on contract with values from oppty.Once Contract is saved I need to populate Contract lookup on Oppty with the newly created contract Id.Is there any other way other than overriding button with visual force/controller.what is the best approach for this ?

share|improve this question
look at ajax toolkit. – Rao Apr 18 '14 at 21:10
@rao can you post some example which will pre populate and on save populate the field with new created record id. – sfdc Apr 18 '14 at 21:14

URL Hacking is only going to help with populating values on the newly created record, it's not capable of updating related records.

You're only real option for this is to use a trigger that updates the lookup on the opportunity whenever the contract is created.

As an aside, you might take this a step back and see if you really need that extra lookup. The contract details are already available as a child relationship to the opportunity and chances are good that you whatever you need that lookup from the opportunity to the contract for could be accomplished with alternate methods (please ask as a separate question).

share|improve this answer
How do I get the opportunity ID in the trigger. – sfdc Apr 21 '14 at 15:46 if you're new to triggers, start with a tutorial (google "Salesforce trigger tutorial), e.g. Writing Your First Trigger. If you're getting stuck, please post a specific issue as a separate question. – Ralph Callaway Apr 22 '14 at 16:34

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.