You need to sign in to do that
Don't have an account?
KULWANT SINGH
Hi, I am new to code. Here i am trying to create a VF page to show all duplicate accounts based on lead name on lead standard page...code is throwing an error says "Invalid conversion from runtime type Lead to Account" for the below code.
public with sharing class MtachedAccountV1Controller {
public lead LD {get;set;}
public account acc {get;set;}
public list<account> alist {get;set;}
public String currentRecordId {get;set;}
public list<account> dupelist {get;set;}
public ApexPages.StandardController controller {get;set;}
public MtachedAccountV1Controller(ApexPages.StandardController controller) {
try
{
ld= new lead();
dupelist = new list<account> ();
this.controller = controller;
this.acc = (Account)controller.getRecord();
currentRecordId = controller.getId();
System.debug('id is..'+currentRecordId );
alist = [select id,name from account where name =: ld.name];
}
Catch (exception e)
{
SYstem.debug(e);
}
}
}
public lead LD {get;set;}
public account acc {get;set;}
public list<account> alist {get;set;}
public String currentRecordId {get;set;}
public list<account> dupelist {get;set;}
public ApexPages.StandardController controller {get;set;}
public MtachedAccountV1Controller(ApexPages.StandardController controller) {
try
{
ld= new lead();
dupelist = new list<account> ();
this.controller = controller;
this.acc = (Account)controller.getRecord();
currentRecordId = controller.getId();
System.debug('id is..'+currentRecordId );
alist = [select id,name from account where name =: ld.name];
}
Catch (exception e)
{
SYstem.debug(e);
}
}
}
All Answers
<apex:page standardController="lead" extensions="MtachedAccountV1Controller">
<apex:form >
<apex:pageBlock title="DuplicateAccounts" >
<apex:pageBlockSection collapsible="false" >
<apex:pageBlockTable value="{!alist}" var="al">
<apex:column headerValue="Account Name" value="{!al.name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Do i need to take ld.name as a string?