function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Create Selectable SObject Table for Editing

Hi All,


I have a requirement to create a VF page showing Leads and Contacts that have a hand-off date from the marketing team to the sales team in a specific time range in a table similar to what is described in the Cookbook


I'm not sure how to bring both leads and contacts into the same view - I understand how to select the leads/contacts but I'm not clear how to get them both into the same list and how to put a date range selector (I can use relative dates such as last week, last month as well as specific date ranges) for the user to select what items they want to see. 


I have a query that finds the leads and contacts I'm looking for and puts them into a list, but am not sure how to access the for the records? 


Here is the code I have so far: 

public with sharing class leadContactCombinedView{
	private SObject record;
	public Boolean selected{get; set;}
    public List<leadContactCombinedView> listLeadContact {get;set;}
        // Universal constructor for any SalesForce object type
	public leadContactCombinedView(SObject obj)
		record = obj;
		selected = false;
    public leadContactCombinedView(){
        // Getter for Lead
	public Lead getLead()
		return (Lead)record;
        // Getter for Contact
	public Contact getContact()
		return (Contact)record;
public List<leadContactCombinedView> generateListLeadContact(){
         for(Lead l : [SELECT id, Website, Title, Street, Status, State, PostalCode, Phone, NumberOfEmployees, MobilePhone, LeadSource, LastName, Industry, HasOptedOutOfEmail, FirstName, Email, Description, Country, Company, City, OwnerID, Primary_Campaign__c, Hand_off_Date__c FROM Lead WHERE  Status = 'Open'])
{ leadContactCombinedView leadItem = new leadContactCombinedView(l); this.ListLeadContact.add(leadItem); } for(Contact c : [SELECT id, Account.Website, Title, Account.BillingStreet, Contact_Status__c, Account.BillingState, Account.BillingPostalCode, Phone, account.NumberOfEmployees, MobilePhone, LeadSource, LastName, Account.Industry, HasOptedOutofEmail, FirstName, Email, Account.Description, Account.BillingCountry, Account.Name, Account.BillingCity, OwnerId, Primary_Campaign__c, Hand_off_Date__c, AccountId FROM Contact WHERE Contact_Status__c = 'Open']){ leadContactCombinedView contactItem = new leadContactCombinedView(c); this.ListLeadContact.add(contactItem); } return listLeadContact; } public List<leadContactCombinedView> getListLeadContact(){ return listLeadContact; } }



Sfd developerSfd developer



You can achieve this using wrapper class, Below code is for an example and you can write it according to your requirements,


Apex Class,


public class testClass{

public Map<Id, sObject> mapObject {get;set;} public List<wrapperClass> getLeadsandContacts(){ mapObject = new Map<Id, sObject>(); List<wrapperClass> cList = new List<wrapperClass>(); for (Contact con : [SELECT Id, Name FROM Contact LIMIT 10]){ cList.add(new wrapperClass(con.Id, 'Contact')); mapObject.put(con.Id, con); } for (Lead lead : [SELECT Id, Name FROM Lead LIMIT 10]){ cList.add(new wrapperClass(lead.Id, 'Lead')); mapObject.put(lead.Id, lead); } return cList; } public class wrapperClass{ public Id obj {get; set;} public String Type {get; set;} public wrapperClass(Id pobj, String pType){ obj = pobj; Type = pType; } }

 Visual force,


<apex:pageBlock >
	<apex:pageBlockTable value="{!LeadsandContacts}" var="rec" >
		<apex:column headerValue="Name" value="{!mapObject[rec.obj].Name}" />