You need to sign in to do that
Don't have an account?
Mamadou Diallo 16
pass record Id to inner class (Compile Error: Variable does not exist)
Hello,
I'm trying to pass the account Id to the new Contact role but I'm getting this error: Compile Error: Variable does not exist: currentAccount.Id
I'm trying to pass the account Id to the new Contact role but I'm getting this error: Compile Error: Variable does not exist: currentAccount.Id
public class AccountWithContactRolesExtension{ Account currentAccount {get; set;} public AccountWithContactRolesExtension(ApexPages.StandardController stdCtrl){ std=stdCtrl; lstInner = new List<innerClass>(); addMore(); selectedRowIndex = '0'; currentAccount = (Account) std.getRecord(); System.Debug('#######current Account Id:' + currentAccount.Id); } public void Add() { count = count+1; // AccountId = getAccount().id; addMore(); } /*Begin addMore*/ public void addMore() { //call to the iner class constructor innerClass objInnerClass = new innerClass(count); //add the record to the inner class list lstInner.add(objInnerClass); system.debug('lstInner---->'+lstInner); }/* end addMore*/ public class innerClass { public String recCount {get;set;} /*Inner Class Constructor*/ public innerClass(Integer intCount) { recCount = String.valueOf(intCount); /*create a new AccountContactRole*/ if(intCount>0 && contactRole == null && currentRecord != null){ AccountContactRole contactRole = new AccountContactRole(AccountId=currentAccount.Id); } }/*End Inner class Constructor*/ }/*End inner Class*/ }Thank you for your help.
try below code
now test and let us know the result
All Answers
public Account currentAccount {get; set;}
complete code is here
Try to update your code like below
public class AccountWithContactRolesExtension{
public Account currentAccount {get; set;}
public AccountWithContactRolesExtension(ApexPages.StandardController stdCtrl){
std=stdCtrl;
lstInner = new List<innerClass>();
addMore();
selectedRowIndex = '0';
currentAccount = (Account) std.getRecord();
System.Debug('#######current Account Id:' + currentAccount.Id);
}
public void Add()
{
count = count+1;
addMore();
}
public void addMore()
{
innerClass objInnerClass = new innerClass(count ,currentAccount);
lstInner.add(objInnerClass);
}
public class innerClass {
public String recCount{get;set;}
public innerClass(Integer intCount , Account acc) {
recCount = String.valueOf(intCount);
if(intCount>0 && contactRole == null && currentRecord != null){
AccountContactRole contactRole = new AccountContactRole(AccountId=acc.Id);
}
}
}
}
Let us know if this will help you
I am glad at least your variable issue is fixed. Can you please provide your VF page code
Thanks
Amit
How you are calling Add method in VF page ?
NOTE:- I hope you are passing the URL while testing page ?
are you getting Account in below line ?
System.Debug('#######current Account Id:' + currentAccount.Id);
System.Debug('#######current Account Id:' + currentAccount.Id);
Yes but not here:
System.Debug('#######current Account Id:' + acc.Id);
public String recCount{get;set;}
public innerClass(Integer intCount , Account acc) {
recCount = String.valueOf(intCount);
System.Debug('#######current Account Id:' + acc.Id);
AccountContactRole contactRole = new AccountContactRole(AccountId=acc.Id);
}
}
Try to update your inner class like above and check account ID. I hope that should work
Error: Compile Error: Inner types are not allowed to have inner types
try below code
now test and let us know the result
Error: Compile Error: Variable does not exist: contactRole
I will let you know tomorrow.
Thank you so much for your help Amit and Raj.