+ Start a Discussion
Hybr1dHybr1d 

Taking more information from Opportunity when creating a new related Contract

Hello!     

 

 

The opportunity/contract relationship is just an example,  but it might work a bit better on your imagination. Important part is that I know how to do this so I can do this myself for other objects :) 

What I am trying to do is the following (in story mode): I am viewing an opportunity, it is going to be Closed - Won, so I would like to create a contract related to this opportunity. I am going to the related list for Contract and click on 'New'. This takes me to the 'Create new Contract' page, the Opportunity look-up field is filled as I created it from the opportunity's related list. I want it to take more information from Opportunity and put it in the Contract fields (say amount, date and description). How do I do this? I am rather unfamiliar with the Salesforce coding and I only have  base knowledge of programming in general, the help function on SF or searching on these forums gave me no results.

 

 

Thanks for reading! 

 

 

 

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Cool_DevloperCool_Devloper

Well, if u wanna pre-populate tha data, then triggers/formula fields won't work!! they will save the information after the record is saved and so you will not be able to see the data on the edit page.

 

For pre-population, you need to create a custom button with sourse as S-Control/VF page which will over-ride the standard new button and would execute the requisite logic for you. Finally, the user will be re-directed to the Edit page with the value pre-populated;)

See this for more info-

Link

Cool_D 

All Answers

WmWm
You can write a Apex trigger which populates all the opp data into the contract object. You might give cross object formula fields a shot also, if you are mostly dealing with the numeric fields.
Cool_DevloperCool_Devloper

Well, if u wanna pre-populate tha data, then triggers/formula fields won't work!! they will save the information after the record is saved and so you will not be able to see the data on the edit page.

 

For pre-population, you need to create a custom button with sourse as S-Control/VF page which will over-ride the standard new button and would execute the requisite logic for you. Finally, the user will be re-directed to the Edit page with the value pre-populated;)

See this for more info-

Link

Cool_D 

This was selected as the best answer
Hybr1dHybr1d
Thanks! I think I should be able to make it work, looking at the code in the link, doesn't seem to be all that sophisticated :)
Cool_DevloperCool_Devloper

Yes, it's definitely easy ;)

Way to go!!

Cool_D 

Hybr1dHybr1d

Apparently it isn't as easy as I expected. What I've got now is the following: /a0B/e?retURL={!Opportunity.Id}&3DCF00N80000004Kaos={!Opportunity.Name}. This link is a Detail Page Button on the Opportunity screen and I want it to create a new Order (the custom object a0B). It opens the Order screen, but the Opportunity field isn't getting filled. I'm not sure if the 3DC00N80000004Kaos is the right link, I looked it up with that Firefox Web Developer app from the Edit screen in Order (not setup). I've also tried it without the '3DCF' part. Any insight on what I might be doing wrong? I'm not sure what the 2 fields are referring to (Opportunity.ID and Opportunity.Name). Thanks.

Cool_DevloperCool_Devloper

You need to check the Source HTML of the edit page and see what is the ID of the field you want to pre-populate!!

Also check, if the URL has the 2 values which you wanna pass over to the create contract page.

Cool_D 

Hybr1dHybr1d
Confused myself a bit here too, I started working from Opportunity to Order(custom) instead of Contract, but I guess the principle is the same. I'm afraid I still can't figure out why it isn't populating though. If I look in the source file and CTRL+F to Opportunity I get the following line: 
<tr><td class="labelCol"><label for="CF00N80000004Kaos">Opportunity</label></td><td class="dataCol col02"><input type="hidden" name="CF00N80000004Kaos_lkid" id="CF00N80000004Kaos_lkid" value="000000000000000" /><input type="hidden" name="CF00N80000004Kaos_lkold" id="CF00N80000004Kaos_lkold" value="null" /><input type="hidden" name="CF00N80000004Kaos_lktp" id="CF00N80000004Kaos_lktp" value="006" /><input type="hidden" name="CF00N80000004Kaos_lspf" id="CF00N80000004Kaos_lspf" value="0" /><input type="hidden" name="CF00N80000004Kaos_mod" id="CF00N80000004Kaos_mod" value="0" /><span class="lookupInput"><input  id="CF00N80000004Kaos" maxlength="255" name="CF00N80000004Kaos" onchange="getElementByIdCS('CF00N80000004Kaos_lkid').value='';getElementByIdCS('CF00N80000004Kaos_mod').value='1';" size="20" tabindex="4" type="text" /><a href="javascript:%20openLookup%28%27%2F_ui%2Fcommon%2Fdata%2FLookupPage%3Flkfm%3DeditPage%26lknm%3DCF00N80000004Kaos%26lktp%3D%27%20%2B%20getElementByIdCS%28%27CF00N80000004Kaos_lktp%27%29.value%2C670%2C%271%27%2C%27%26lksrch%3D%27%20%2B%20escapeUTF%28getElementByIdCS%28%27CF00N80000004Kaos%27%29.value.substring%280%2C%2080%29%29%29" id="CF00N80000004Kaos_lkwgt" onclick="setLastMousePosition(event)" tabindex="4" title="Opportunity Lookup (New Window)"><img src="/s.gif" alt="Opportunity Lookup (New Window)"  class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="Opportunity Lookup (New Window)"/></a></span></td><td class="labelCol"><label for="00N80000004KTPB">Current planned end date</label></td><td class="dataCol"><span class="dateInput dateOnlyInput"><input  id="00N80000004KTPB" name="00N80000004KTPB" onfocus="DatePicker.pickDate(false, '00N80000004KTPB', false);" size="12" tabindex="10" type="text" /><span class="dateFormat">[&nbsp;<a href="javascript:DatePicker.insertDate('12/16/2009', '00N80000004KTPB', true);" tabindex="10">12/16/2009</a>&nbsp;]</span></span></td></tr
Loads of links in that. On top of that, I'm not even sure if it's the right line that I took out of the source file. 

So I'm trying to get the Opportunity Name field from Opportunity to automatically fill in in the Order tab Opportunity field with this code: /a0B/e?retURL={!Opportunity.Id}&32Fa0B80000005Ouh0={!Opportunity.Name} but so far all it does is open a new window with the "New Order" page. 

So from: http://img682.imageshack.us/i/opp.jpg/ to: http://img682.imageshack.us/i/ordl.jpg/.

Thanks again for the answers :)