Search code examples
salesforceapex-codevisualforce

How to prepopulate a standard lookup field in a standard object?


Setup:

On my Event Object, I want to prepopuate the 'assigned to' field with a different user name 'Babe Ruth' than the current owner. This field is a Lookup field. The field name is Owner, if that makes a difference. We're implementing this by modifying the url with S-Controls that are calling Apex.

Problem:

  1. I'm not sure how to get the field name for the field. I've inspected the element, and it says to be evt_1. Is there a way to verify that is the absolute field name, and not a relative one?

  2. I can't get the page to save with my changes. In the URL hacking I add: evt_1=Babe%20Ruth&saveURL=..., which successfully displays the changes, but when I click save, the field is not saved with 'Babe Ruth', but my name as Owner!

I have looked at this reference and others and am still stuck.

http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html


Solution

  • If you look in the link you send, it says:

    The best way that I've found to get the ID of the field that you want populated is by navigating to the field in setup. For example, if I want to prepopulate ObjectDetail_c.TextField_c, I would go to Setup => Create => Objects => ObjectDetail => TextField, which takes me to to the URL

    Once you know the id of the field you want to populate, you use <fieldId>=TextValue&_lkid=<recordId>. Using the example in the link, if the fieldId is CF00NA0000005JzZX, then the parameters are

    CF00NA0000005JzZX=Babe+Ruth&CF00NA0000005JzZX_lkid=<userId>
    

    Where < userId> is the id of the Babe Ruth's user record.