[SalesForce] How to pass parameter TO a Visualforce page from a link in an email

Here's what I am trying to do:

1) User creates record A.
2) Time-based workflow sends an email to the Record A creator based on a date field in the record.
3) The email template has a URL link.
4) The URL links to a Visualforce page that is basically a form with fields to be filled out (this Visualforce page is in a managed package) and a save button that creates a new User record.
5) When the User clicks the URL link in the email, the Visualforce page opens in a new window.
6) I would like to pass the values of the fields in record A to pre-fill the Visualforce page fields.

Here's my link:

<a href="https://cs19.visual.force.com/apex/CloneThisUser?Desktop=true&Id={!Pending_User__c.User_to_CloneId__c}&formGroupInputSmall={!Pending_User__c.First_Name__c}

And here's the code from the relevant section of the Visualforce page:

<div class="form-group form-group-sm">
      <!-- <apex:outputLabel styleClass="col-sm-2 control-label" for="formGroupInputSmall">First Name</apex:outputLabel> -->
      <div class="col-xm-11 col-sm-12">
          <apex:inputField html-placeholder="First Name" styleClass="form-control FirstNameInput"  value="{!u.FirstName}" id="formGroupInputSmall"/>
      </div>
    </div>

I have only included the first field I would like to pass the parameter to, in order to keep this post simple.

The link passes the User_to_Clone_Id__c just fine but does not fill in the "First Name" field with the value of the First_Name__c .

What am I doing incorrectly? Thanks.

Best Answer

Do you need all of the parameters or can you simply pass the ID of the record A containing the values?

I would change my link to pass in the ID of the Record A

?dataid={recorded}

Then I would use a controller for the VF page that in its constructor would query for the Record A record from the URL param and populate the values of u.FirstName etc.

If the value are populated in the controller when the page loads it will be prepopulated as desired.

If you are concerned about the ID being exposed, use AES encryption to encrypt the ID and put it in the email template (May need a field populated by a trigger to store it to use in the email). Then decrypt it in the controller

Related Topic