How to pre-populate the values in Salesforce

    On creation of new record probably you would like to have some default values, in that case we can do the below approaches

  1. If it is a custom field make use of default value option
  2. If it is a standard field then probably what you can do is you can override the new button by passing the desire values in URL. But this will not suffice all the requirements such as when you want to pre-populate more field values using URL approach is going to be pathetic situation.
  3. Here is a alternative solution for all this just with a little java script. Create a new s-control and use the below code (which will set the values using post method so that these values will not be visible in the URL)
  4. <!-- This example helps you out to pre-populate the account field in the new contact creation -->
    <script type="text/javascript" src="/soap/ajax/15.0/connection.js" > </script> 
    <script type="text/javascript" src="/js/functions.js"></script>
    <script type="text/javascript">
    function LoadingA()
    var returnURL = '{!$Request.retURL}';
    var f= parent.document.createElement('form');
    var ch=parent.document.createElement('input');'accid'; //This is the id of that component'accid';
    ch.value='0015000000Upz3h';//This is the real value which you would like to populate on the account lookup
    alert('error :'+error);
    <body id="thisBody" onload=LoadingA();>

    Once you are done with this then you can use this s-control to override your new button which will pre-populate the value in the account lookup to the mentioned account id.

This entry was posted in Salesforce Tips & Tricks, Visualforce. Bookmark the permalink.

One Response to How to pre-populate the values in Salesforce

  1. Prathik says:

    Hi, is it possible to populate fields from external website?

    For e.g, suppose I have a field called conversion rate and I want that field to update automatically from the info it gets from Yahoo Finance.

    How do you do that?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s