0

How do I pass a lead email address to an IFRAME? I did the following steps:

Created a new test lead.

Went into gear icon > Setup > Custom Code > VisualForce Pages, and created a new VisualForce Page like so:

<apex:page>
  <apex:iframe src="https://example.com/salesforce/test.php?id={!$CurrentPage.parameters.id}" scrolling="true" id="iframe-test"/>
</apex:page>

In my test.php page on my web server, I added this:

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
header('Content-Type: text/plain');
print_r($_GET);
echo "\n\nDONE";

Exited setup.

Clicked on my lead (to show a single lead) and chose gear icon > Edit Page.

Added a new tab beside News called CUSTOM.

Clicked that tab in the page editor and dragged a VisualForce (page object) to that tab and set it to my new custom VisualForce page that I created.

Saved and Activated this change for the Org.

Exited the page editor to return to the single Lead view.

Clicked the CUSTOM tab.

Okay, so I can see an ID is passed to me of the calling page. However, is there an easy way to pass URL parameters to my IFRAME such as:

Lead.Email
Lead.MobilePhone
Lead.Phone
Lead.Name
Lead.FirstName
Lead.LastName

And, moreover, can these be URL-encoded so that they pass properly to my IFRAME?

Note I was able to get something like {!$ObjectType.Lead.Fields.Email} to give me an email, but it appeared in an unusuable format like the following when I viewed it in my IFRAME:

common.api.soap.wsdl.Field@26ca801c
1

The trick is to change the APEX code to use the Lead standard controller, and then the Email is pulled with {!URLENCODE(Lead.Email)}.

<apex:page standardController="Lead">
  <apex:iframe src="https://example.com/salesforce/test.php?id={!$CurrentPage.parameters.id}&email={!URLENCODE(Lead.Email)}" scrolling="true" id="iframe-test"/>
</apex:page>

That will give you the safe, URL-encoded version of the Lead.Email string.

Other parameters you can get with the Lead object are:

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_lead.htm#!

Note, however, that when you convert this Lead into a Customer, it will disappear from Leads and will be available under Contact. So, you have to repeat this process all over again to customize the Contact page. (Note that the Contact page doesn't contain Leads, by the way -- only converted customers.)

So, in the APEX code, it would look like:

<apex:page standardController="Contact">
  <apex:iframe src="https://example.com/salesforce/test.php?id={!$CurrentPage.parameters.id}&email={!URLENCODE(Contact.Email)}" scrolling="true" id="iframe-test"/>
</apex:page>

As you can see, I switched Lead with Contact in the above code. Fields such as Email, MobilePhone, Phone, Name, FirstName, and LastName are all accessible under Contact just as they are under Lead.

The full Contact object reference is here:

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contact.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.