+ Start a Discussion
jai.sjai.s 

Error: MultipleObjectClass Compile Error: Constructor not defined: [MultipleObjectClass.wrapperclass].<Constructor>(LIST<grandparent__c>) at line 30 column 23

Hi,

I am creating a vf page to dispaly grand parent, parent, child records in singletable, but iam getting below error in controller class, please help me to solve this error.

VF Page:
<apex:page sidebar="false" controller="MultipleObjectClass">
<apex:pageBlock>
<apex:pageBlockTable value="{!grandparentWraplist}" var="g">
<apex:column value="{!g.doc1.name}"/>
<apex:column value="{!g.doc1.age__c}" />
<apex:column>
<apex:pageBlockTable value="{!d.parentlist}" var="p">
<apex:column value="{!p.name}"/>
<apex:column>
<apex:pageBlockTable value="{!p.childList}" var="c">
<apex:column value="{!c.name}"/>
<apex:column value="{!c.phone__c}"/>
</apex:pageBlockTable>
</apex:column>
</apex:pageBlockTable>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Controller:
public class MultipleObjectClass {
public list<wrapperclass> grandparentWraplist{get;set;}
public list<grandparent__c> doclist {get;set;}
public list<parent__c> plist {get;set;}
map<ID,list<parent__c>> grandParentListMap {get; set;}
set<ID> docIDs=new set<ID>();
map<ID, list<grandparent__c>> docMap=new map<ID, list<grandparent__c>>();

public MultipleObjectClass (){
doclist=[Select id,name From grandparent__C];
grandParentListMap=new map<ID,list<parent__c>>();
 grandparentWraplist=new list<wrapperclass>();
 
if(doclist.size()>0){
for(grandparent__c doc:doclist){
docIDs.add(doc.id);
docMap.put(doc.id, new list<grandparent__c>());
}
plist =[Select id,name,grandparent__c,(select id,name,phone__c from childs__r) From parent__c where grandparent__c=:docIDs];
}
if(plist.size()>0){
for(parent__c pat:plist){
if(!grandParentListMap .containskey(pat.grandparent__c)){
grandParentListMap.put(pat.grandparent__c, new list<parent__c>());
}
grandParentListMap.get(pat.grandparent__c).add(pat);
}
for(id patid:grandParentListMap.keyset()){

grandparentWraplist.add(new wrapperclass(docMap.get(patid)),grandParentListMap.get(patid)); // in this line iam getting error
}
}

}

Public class wrapperclass{
public grandparent__c doc1{get;set;}
public list<parent__c> childlist{get; set;}

public wrapperclass(grandparent__c doc1, list<parent__c> childlist{
doc1=doc2;
childlist=childlist;
}
}
}

Thanks in Advance!!

 
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello,

The constructor of your wrapper class is expecting a single grandparent__c but you are trying to pass a List of it.
 
public wrapperclass(grandparent__c doc1, list<parent__c> childlist){
 
grandparentWraplist.add(new wrapperclass(docMap.get(patid)),

Notice that your docMap returns a List<grandparent__c> and your constructor expects just one. You have to change your constructor or try another approach.

Regards 

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.