You need to sign in to do that
Don't have an account?
Ap30
wrapper class to display two related custom object records in a single table
Hello All,
I'm getting below error in my Apex. Please guide me.
Error: Compile Error: Constructor not defined: [TrainingDataWrapperController.wrapRecord].<Constructor>(Trainers_Detail__c) at line 13 column 36
line 13 ---> wrapRecordList.add(new wrapRecord(t));
================code===============
public class TrainingDataWrapperController {
//Our collection of the class/wrapper objects wrapRecord
public List<wrapRecord> wrapRecordList{get; set;}
public list<custobj1> obj1{get;set;}
public list<custobj2> obj2{get;set;}
public TrainingDataWrapperController (){
if(wrapRecordList == null) {
wrapRecordList = new List<wrapRecord>();
for (custobj1 t: [Select Id, First_Name__c, Last_Name__c, Education__c, Technology__c ,(Select Name From custobj2) From custobj1 Limit 1]){
// As each detail is processed we create a new wrapRecord object and add it to the wrapRecordList
wrapRecordList.add(new wrapRecord(t));
}
}
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects.
public class wrapRecord {
public custobj1 td {get; set;}
public custobj2 tdeal {get; set;}
//This is the contructor method. When we create a new wrapRecord object.
public wrapRecord (custobj1 tds,custobj2 tdeals) {
td = tds;
tdeal = tdeals;
}
}
}
I'm getting below error in my Apex. Please guide me.
Error: Compile Error: Constructor not defined: [TrainingDataWrapperController.wrapRecord].<Constructor>(Trainers_Detail__c) at line 13 column 36
line 13 ---> wrapRecordList.add(new wrapRecord(t));
================code===============
public class TrainingDataWrapperController {
//Our collection of the class/wrapper objects wrapRecord
public List<wrapRecord> wrapRecordList{get; set;}
public list<custobj1> obj1{get;set;}
public list<custobj2> obj2{get;set;}
public TrainingDataWrapperController (){
if(wrapRecordList == null) {
wrapRecordList = new List<wrapRecord>();
for (custobj1 t: [Select Id, First_Name__c, Last_Name__c, Education__c, Technology__c ,(Select Name From custobj2) From custobj1 Limit 1]){
// As each detail is processed we create a new wrapRecord object and add it to the wrapRecordList
wrapRecordList.add(new wrapRecord(t));
}
}
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects.
public class wrapRecord {
public custobj1 td {get; set;}
public custobj2 tdeal {get; set;}
//This is the contructor method. When we create a new wrapRecord object.
public wrapRecord (custobj1 tds,custobj2 tdeals) {
td = tds;
tdeal = tdeals;
}
}
}
Please check this code:- In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
All Answers
You are getting an error because Constructor is taking 2 arguments but you have passed only 1 argument.
Here you have given only one argument in wrapRecord.
But here wrapRecord is taking 2 arguments
You can take reference from this below code.
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
Thanks and Regards
Suraj Tripathi.
List index out of bounds: 0 An unexpected error has occurred. Your development organization has been notified.
Please check this code:- In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
objects Trainingdeal__c and Trainer__c from TrainingDeal__c object want only name and from Trainer__c object want yo display Firstname,lastname,education, technology
public class wrapperdemo{
public list<wrapRecord> wrapRecordlist{get;set;}
public list<TrainingDeal__c> obj1{get;set;}
public list<Trainer__c> obj2{get;set;}
public wrapperdemo(){
if(wrapRecordlist==null){
wrapRecordlist=new list<wrapRecord>();
for(TrainingDeal__c t:[select Name(select FirstName__c, LastName__c, Education__c from Trainer__c) from TrainingDeal__c]){
if(!.Trainer__c.isEmpty()){
for(Trainer__c t1 :Trainer__c){
wrapRecordlist.add(new wrapRecord(t,t1));
}
} }
}
}
public class wrapperdemo{
public TrainingDeal__c td{get;set;}
public Trainer__c tdeal{get;set;}
public wrapRecord(TrainingDeal__c tds,Trainer__c tdeas){
td=tds;
tdeal=tdeals;
}
}
}