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
sachitanand kumarsachitanand kumar 

Hi All, I write a class for vf page for display duplicate lead in vf page.i got the Error: leaddup Compile Error: Illegal assignment from List<AggregateResult> to List<Lead> . i m basically admin so i can't understand about error any help appreciated

This is class
-------------------------------------------------------------------------
public class leaddup {

    public List<lead>ac{get;set;}
    public leaddup(){
    ac =[SELECT name,email FROM lead ];
    }
    public void getbyname(){
       ac=[SELECT name,count(Id) FROM lead GROUP BY name HAVING count(Id)>1];
    }
     public void getbyemail(){
       ac=[SELECT email,count(Id) FROM lead GROUP BY email HAVING count(Id)>1];
    }
}
--------------------------------------------------
This is vf
---------------------------------------------------------------------
<apex:page controller="leaddup">
    <apex:form >
        <apex:pageblock title="Duplicate lead">
            <apex:pageBlockButtons >
                <apex:commandButton value="based on name" action="{!getbyname}"/>
                <apex:commandButton value="based on email" action="{!getbyemail}"/>
            </apex:pageBlockButtons>
                    <apex:PageBlockTable value="{!ac}" var="a">
                        <apex:Column value="{!a.Name}"/>
                        <apex:Column value="{!a.email}"/> 
                    </apex:PageBlockTable>
               
        </apex:pageblock>
    </apex:form>
</apex:page>
Best Answer chosen by sachitanand kumar
LBKLBK
Aggregate query does not return you a list of standard or custom object.

Your code has to be like this below.
public class leaddup {

    public List<lead>ac{get;set;}
	public List<AggregateResult> ac1 {get; set;}
	public List<AggregateResult> ac2 {get; set;}
	public Boolean bName {get; set;}
	public Boolean bEmail {get; set;}
	public Boolean bLead {get; set;}
	
    public leaddup(){
		bName = false;
		bEmail = false;
		bLead = true;
		ac =[SELECT name,email FROM lead];
    }
    public void getbyname(){
		bName = true;
		bEmail = false;
		bLead = false;
		ac1=[SELECT name,count(Id) count1 FROM lead GROUP BY name HAVING count(Id)>1];
    }
     public void getbyemail(){
		bName = false;
		bEmail = true;
		bLead = false;
		ac2=[SELECT email,count(Id) count1 FROM lead GROUP BY email HAVING count(Id)>1];
    }
}


<apex:page controller="leaddup">
    <apex:form >
        <apex:pageblock title="Duplicate lead">
			<apex:pageBlockButtons >
				<apex:commandButton value="based on name" action="{!getbyname}"/>
				<apex:commandButton value="based on email" action="{!getbyemail}"/>
			</apex:pageBlockButtons>
			<apex:PageBlockTable value="{!ac}" var="a"  rendered="{!bLead}">
				<apex:Column value="{!a.Name}"/>
				<apex:Column value="{!a.email}"/> 
			</apex:PageBlockTable>
			<apex:PageBlockTable value="{!ac1}" var="a"  rendered="{!bName}">
				<apex:Column value="{!a['Name']}"/>
				<apex:Column value="{!a['count1']}"/> 
			</apex:PageBlockTable>
			<apex:PageBlockTable value="{!ac2}" var="a"  rendered="{!bEmail}">
				<apex:Column value="{!a['Email']}"/>
				<apex:Column value="{!a['count1']}"/>  
			</apex:PageBlockTable>               
        </apex:pageblock>
    </apex:form>
</apex:page>
Let me know if this works.

All Answers

Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi, 

Please try this code, 

Apex Code : 
public with sharing class DuplicateLeadExt {
    public List<Lead> duplicateLeadList{get;set;}
    public Lead thisLead{get;set;}
    public DuplicateLeadExt(ApexPages.StandardController controller) {
        duplicateLeadList = new List<Lead>();
        List<String> fields = new List<String>();
        fields.add('Name');
        fields.add('Email');
        controller.addFields(fields);
        thisLead = (Lead)Controller.getRecord();    
    }
    
    public void getbyname(){
       
       duplicateLeadList = [SELECT Name,Email FROM Lead WHERE Name =:thisLead.Name AND Id <> :thisLead.Id];
    }
     public void getbyemail(){
       duplicateLeadList = [SELECT Name,Email FROM Lead WHERE Email = :thisLead.Email AND Id <> :thisLead.Id];
    }

}

Visualforce Code : 
 
<apex:page StandardController="Lead" extensions="DuplicateLeadExt">
    <apex:form >
        <apex:pageBlock >
            <apex:PageBlockButtons >
                 <apex:commandButton value="based on name" action="{!getbyname}" rerender="panelId"/>
                 <apex:commandButton value="based on email" action="{!getbyemail}" rerender="panelId"/>
            </apex:PageBlockButtons>
            
            <apex:outputPanel id="panelId">
                <apex:PageBlockTable value="{!duplicateLeadList}" var="duplicateLead">
                    <apex:Column value="{!duplicateLead.Name}"/>
                    <apex:Column value="{!duplicateLead.email}"/> 
                </apex:PageBlockTable>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Thanks
Prosenjit
LBKLBK
Aggregate query does not return you a list of standard or custom object.

Your code has to be like this below.
public class leaddup {

    public List<lead>ac{get;set;}
	public List<AggregateResult> ac1 {get; set;}
	public List<AggregateResult> ac2 {get; set;}
	public Boolean bName {get; set;}
	public Boolean bEmail {get; set;}
	public Boolean bLead {get; set;}
	
    public leaddup(){
		bName = false;
		bEmail = false;
		bLead = true;
		ac =[SELECT name,email FROM lead];
    }
    public void getbyname(){
		bName = true;
		bEmail = false;
		bLead = false;
		ac1=[SELECT name,count(Id) count1 FROM lead GROUP BY name HAVING count(Id)>1];
    }
     public void getbyemail(){
		bName = false;
		bEmail = true;
		bLead = false;
		ac2=[SELECT email,count(Id) count1 FROM lead GROUP BY email HAVING count(Id)>1];
    }
}


<apex:page controller="leaddup">
    <apex:form >
        <apex:pageblock title="Duplicate lead">
			<apex:pageBlockButtons >
				<apex:commandButton value="based on name" action="{!getbyname}"/>
				<apex:commandButton value="based on email" action="{!getbyemail}"/>
			</apex:pageBlockButtons>
			<apex:PageBlockTable value="{!ac}" var="a"  rendered="{!bLead}">
				<apex:Column value="{!a.Name}"/>
				<apex:Column value="{!a.email}"/> 
			</apex:PageBlockTable>
			<apex:PageBlockTable value="{!ac1}" var="a"  rendered="{!bName}">
				<apex:Column value="{!a['Name']}"/>
				<apex:Column value="{!a['count1']}"/> 
			</apex:PageBlockTable>
			<apex:PageBlockTable value="{!ac2}" var="a"  rendered="{!bEmail}">
				<apex:Column value="{!a['Email']}"/>
				<apex:Column value="{!a['count1']}"/>  
			</apex:PageBlockTable>               
        </apex:pageblock>
    </apex:form>
</apex:page>
Let me know if this works.
This was selected as the best answer