Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Created June 4, 2016 19:41
Show Gist options
  • Save douglascayers/1d2ac7d25c7a93d32ebca41730eda78e to your computer and use it in GitHub Desktop.
Save douglascayers/1d2ac7d25c7a93d32ebca41730eda78e to your computer and use it in GitHub Desktop.
Simple Visualforce template for displaying converted lead records. Once a lead is converted the standard detail page is no longer accessible, must use reports or visualforce.
/**
* https://twitter.com/Joy_SH/status/738087166547398656
* https://help.salesforce.com/apex/HTViewSolution?id=000175908&language=en_US
*/
public with sharing class LeadConvertedViewController {
public Lead record { get; private set; }
public LeadConvertedViewController( ApexPages.StandardController stdController ) {
this.record = (Lead) queryRecord( stdController.getId() );
}
private SObject queryRecord( ID recordId ) {
// https://douglascayers.wordpress.com/2015/10/08/salesforce-how-to-select-all-fields-with-soql-in-apex/
DescribeSObjectResult describeResult = recordId.getSObjectType().getDescribe();
List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() );
String query =
' SELECT ' +
String.join( fieldNames, ',' ) +
' FROM ' +
describeResult.getName() +
' WHERE ' +
' id = :recordId ' +
' LIMIT 1 '
;
List<SObject> records = Database.query( query );
return ( records.size() > 0 ) ? records[0] : null;
}
}
<apex:page standardController="Lead" extensions="LeadConvertedViewController" readOnly="true">
<apex:pageBlock>
<apex:pageBlockSection columns="1">
<!--
Unfortunately, you have to build out the page yourself
to show chatter feed, fields and any related lists.
You cannot use the <apex:detail> tag that would naturally
render the user's appropriate page layout, will get Insufficient Privileges.
-->
<apex:outputField value="{!record.firstName}"/>
<apex:outputField value="{!record.lastName}"/>
<apex:outputField value="{!record.company}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
@douglascayers
Copy link
Author

To make the converted lead data accessible by your users, you can create a lead with converted info report as described here: https://help.salesforce.com/apex/HTViewSolution?id=000175908&language=en_US

If you want to add some flavor and provide a visualforce page to display other data, related lists, etc. Then from the report have a link to the visualforce page (the link can be defined as a custom URL field on the lead and added to the report).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment