+ Start a Discussion
srinivas pulipatisrinivas pulipati 

hi,i am writing apex code but i got error please solve this error ,vf page also execute but apex code have error

Apexcode:

public with sharing class relatedcontacts {
public relatedcontacts(){
AccountData();
}
list<Account> lstacc = new list<Account>();
list<accountwrapclass>  lstAccwrap = new list<accountwrapclass>();//[Error] Error: Compile Error: Invalid type: accountwrapclass at line 6 column 47
public list<accountwrapclass> getAccounts() {

// lstacc=[select id,name,phone,website,taxable__c from Account];
return lstAccwrap ;
}
public void AccountData(){
for(Account acc:[select id,name,phone,website from Account]){
accountwrapclass objacc = new accountwrapclass();
objacc.Name = acc.Name;
objacc.accid = acc.id;
objacc.phone = acc.phone;
objacc.website = acc.website;
/*if(acc.taxable__C == true){
objacc.taxable ='yes';
}else{
objacc.taxable ='NO';
}*/
lstAccwrap.add(objAcc);
}
}
}

Vfcode:

<apex:page controller="relatedcontacts">
<script>
function showModal(val){
//window.showModalDialog('/apex/secondpage?id='+val);
window.showModalDialog('/apex/contactswithcheckbox?id='+val);
}
</script>
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Records">
<apex:pageBlockTable value="{!Accounts}" var="a">
<apex:column headerValue="Name">
<apex:commandlink value="{!a.Name}" onclick="showModal('{!a.accid}')" />
</apex:column>
<apex:column headerValue="phone" >
{!a.phone}
</apex:column>
<apex:column headerValue="website" >
{!a.website}
</apex:column>
<apex:column headerValue="taxable" >
{!a.taxable}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Best Answer chosen by srinivas pulipati
Abhishek BansalAbhishek Bansal
Hi Srinivas,

In your apex class you have not defined the wrapper class, that is why you are getting error.
I have modified your controller class.
Please change class code with below code:
public with sharing class relatedcontacts {
	public relatedcontacts(){
		AccountData();
	}
	list<Account> lstacc = new list<Account>();
	list<accountwrapclass>  lstAccwrap = new list<accountwrapclass>();//[Error] Error: Compile Error: Invalid type: accountwrapclass at line 6 column 47
	public list<accountwrapclass> getAccounts() {

		// lstacc=[select id,name,phone,website,taxable__c from Account];
		return lstAccwrap ;
	}
	
	public void AccountData(){
		for(Account acc:[select id,name,phone,website from Account]){
			accountwrapclass objacc = new accountwrapclass();
			objacc.Name = acc.Name;
			objacc.accid = acc.id;
			objacc.phone = acc.phone;
			objacc.website = acc.website;
			/*if(acc.taxable__C == true){
				objacc.taxable ='yes';
			}else{
				objacc.taxable ='NO';
			}*/
			lstAccwrap.add(objAcc);
		}
	}
	
	public class accountwrapclass{
		public String Name {get;set;}
		public Id accid {get;set;}
		public Integer phone {get;set;}
		public String website {get;set;}
	}
}
Let me know if you have any issue.

Thanks,
Abhishek

All Answers

Abhishek BansalAbhishek Bansal
Hi Srinivas,

In your apex class you have not defined the wrapper class, that is why you are getting error.
I have modified your controller class.
Please change class code with below code:
public with sharing class relatedcontacts {
	public relatedcontacts(){
		AccountData();
	}
	list<Account> lstacc = new list<Account>();
	list<accountwrapclass>  lstAccwrap = new list<accountwrapclass>();//[Error] Error: Compile Error: Invalid type: accountwrapclass at line 6 column 47
	public list<accountwrapclass> getAccounts() {

		// lstacc=[select id,name,phone,website,taxable__c from Account];
		return lstAccwrap ;
	}
	
	public void AccountData(){
		for(Account acc:[select id,name,phone,website from Account]){
			accountwrapclass objacc = new accountwrapclass();
			objacc.Name = acc.Name;
			objacc.accid = acc.id;
			objacc.phone = acc.phone;
			objacc.website = acc.website;
			/*if(acc.taxable__C == true){
				objacc.taxable ='yes';
			}else{
				objacc.taxable ='NO';
			}*/
			lstAccwrap.add(objAcc);
		}
	}
	
	public class accountwrapclass{
		public String Name {get;set;}
		public Id accid {get;set;}
		public Integer phone {get;set;}
		public String website {get;set;}
	}
}
Let me know if you have any issue.

Thanks,
Abhishek
This was selected as the best answer
srinivas pulipatisrinivas pulipati
thank you