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
Conor Bradley 5Conor Bradley 5 

change visualforce page so I can edit records

Hi, I have a VF page that show 'Similar Leads' based on matching by email. Because in our org it is okay to have the same lead twice as they could be for different events. Any way I have a VF page with apex class that shows the 'similar leads'. Howvwer this just shows the leads, doesnt allow you to edit them. Can you suggest how this could be done? Code below:

Apex: 
public class GetLeadsApexController {
    private final Lead lead;
    
    public GetLeadsApexController(ApexPages.StandardController stdController) {
        if (!Test.isRunningTest()) {
            stdController.addFields(new List<String>{'Name', 'Email', 'OwnerId', 'Status', 'Product_of_Interest__c'});
        }
        this.lead = (Lead)stdController.getRecord();
    }

    public List<Lead> getLeads () {             
        List<Lead> leads = [
            SELECT Id, Name, Email, Status, OwnerId, Product_of_Interest__c FROM Lead WHERE Id != :lead.Id AND Email = :lead.Email
        ];
        return leads;
    }
}

VF Page:
<apex:page lightningStylesheets="true" standardController="Lead" extensions="GetLeadsApexController" tabStyle="Lead" sidebar="false">
 <apex:pageBlock >
          <apex:pageBlockTable value="{! leads }" var="ct" id="leads_list">
            <apex:column value="{! ct.name}" />
            <apex:column value="{! ct.email}" />           
            <apex:column value="{! ct.Product_of_Interest__c}" />
            <apex:column value="{! ct.OwnerId}" />
            <apex:column value="{! ct.Status}" />
            <apex:inputCheckbox />
          </apex:pageBlockTable>    
      </apex:pageBlock>
</apex:page>


Many Thanks
Conor
 
Best Answer chosen by Conor Bradley 5
Waqar Hussain SFWaqar Hussain SF
Hi Conor,

Try below code
<apex:page lightningStylesheets="true" standardController="Lead" extensions="GetLeadsApexController" tabStyle="Lead" sidebar="false">
 <apex:pageBlock >
          <apex:pageBlockTable value="{! leads }" var="ct" id="leads_list">
            <apex:column headerValue="Edit">
				<apex:outputLink value="{!URLFOR($Action.Lead.Edit, ct.Id, null, true)}">Edit</apex:outputLink>
			</apex:column>
			<apex:column value="{! ct.name}" />
            <apex:column value="{! ct.email}" />           
            <apex:column value="{! ct.Product_of_Interest__c}" />
            <apex:column value="{! ct.OwnerId}" />
            <apex:column value="{! ct.Status}" />
            <apex:inputCheckbox />
          </apex:pageBlockTable>    
      </apex:pageBlock>
</apex:page>

 

All Answers

Waqar Hussain SFWaqar Hussain SF
Hi Conor,

Try below code
<apex:page lightningStylesheets="true" standardController="Lead" extensions="GetLeadsApexController" tabStyle="Lead" sidebar="false">
 <apex:pageBlock >
          <apex:pageBlockTable value="{! leads }" var="ct" id="leads_list">
            <apex:column headerValue="Edit">
				<apex:outputLink value="{!URLFOR($Action.Lead.Edit, ct.Id, null, true)}">Edit</apex:outputLink>
			</apex:column>
			<apex:column value="{! ct.name}" />
            <apex:column value="{! ct.email}" />           
            <apex:column value="{! ct.Product_of_Interest__c}" />
            <apex:column value="{! ct.OwnerId}" />
            <apex:column value="{! ct.Status}" />
            <apex:inputCheckbox />
          </apex:pageBlockTable>    
      </apex:pageBlock>
</apex:page>

 
This was selected as the best answer
Conor Bradley 5Conor Bradley 5
Thanks Waqar !