function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AduttAdutt 

Wrapper Class issue.

Hi All,

I am trying to get the count() of a particular set of accounts based on the search criteria. In the controller everything looks good and also in the debug logs , I am getting the desired outputs. The problem is when I try fetching the aggregate result in the page, I am getting the following error : Unknown property 'String.inti'

 

I am posting my code hereby,

 

page:

<apex:page controller="accountSearch">
<script>
function information()
{
method1();
alert('ddd');
var pbs1=true;
alert(pbs1);
}
</script>
<apex:form >
<apex:pageBlock >
<apex:outputLabel value="Enter your search text:" >
<apex:inputText value="{!searchVar}">
</apex:inputText>
</apex:outputLabel>
<apex:commandLink value="Search" action="{!getAccounts}" />


<apex:pageBlockTable value="{!accList}" var="acc" rendered="{!IF(count,true,false)}" >
<apex:column headerValue="Account Name">
<apex:commandLink action="{!getID}" value="{!acc.name}">
<apex:param name="var1" value="{!acc.id}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>

<apex:dataTable value="{!wrapList}" var="wrp" rendered="{!IF(count,true,false)}" border="1" >
<apex:column >
<apex:facet name="header">Count:</apex:facet>
<apex:outputText value="{!wrp.inti}"></apex:outputText>
</apex:column>
</apex:dataTable>

<apex:actionFunction name="method1" action="{!method1Action}"/>

<apex:pageBlockSection title="Account Information" rendered="{!IF(op1,true,false)}" collapsible="false" onclick="information()">
<apex:outputPanel rendered="{!IF(pbs1,true,false)}">
<apex:repeat value="{!selectedAccount}" var="selectedAcc" >
<td>
<tr>
<apex:pageBlockSection >
<apex:outputField value="{!selectedAcc.Name}"></apex:outputField>
</apex:pageBlockSection>
</tr>
</td>
</apex:repeat>

</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller :

public with sharing class accountSearch {


public String olId { get; set; }
public String searchVar { get; set; }
public String var;
public String var1{get;set;}
public Account selectedAccount{get;set;}
public list<Account> accList = new list<Account>();
public boolean op1=false;
public boolean pbs1=false;
public boolean count=false;
public list<wrapClass>wrapList = new list<wrapClass>();
public list<AggregateResult> agr = new list<AggregateResult>();

public PageReference getAccounts() {
var='%'+searchVar+'%';
system.debug('aaaaaaaaaaaa'+var);
accList = [Select id,name,NumberOfEmployees from account where name LIKE:var ];
system.debug('vvvvv'+accList);
count=true;
getResult();
system.debug('ddddddddddddddddd');
return null;
}

public list<wrapClass> getResult()
{
agr=[Select name,Count(id) quantity from Account where id IN : accList GROUP BY name ];
system.debug('ccccccccccc'+agr);
String str='';
for(AggregateResult a:agr)
{
str +=a.get('quantity');
system.debug('nnnnnnnn'+str);
wrapList.add(new wrapClass(str)); ---here I am adding string to the wrapper class list
}
system.debug('rrrrrrrrrrr'+wrapList);
return wrapList;
}

public list<Account> getAccList(){
return accList;
}
public String getID()
{
String strId = apexpages.currentpage().getparameters().get('var1');
system.debug('lllllllllll'+strId);
selectedAccount=[Select name,OwnerId,Site,AccountSource,AnnualRevenue,NumberOfEmployees,Fax,Industry,Ownership,Phone,Rating,Type from Account
where id=:strId];
op1=true;
pbs1=false;
return null ;
}
public String getWrapList() {
return null ;
}

public String getWrp(){
return null;
}


public Boolean getOp1()
{
return op1;
}

public void setOp1(Boolean abc)
{
this.op1=abc;
}
public Boolean getPbs1()
{
return pbs1;
}

public void setPbs1(Boolean abc)
{
this.pbs1=abc;
}
public void method1Action()
{
pbs1=true;
}
public Boolean getCount()
{
return count;
}

public void setcount(Boolean abc)
{
this.count=abc;
}

public class wrapClass{
public wrapClass wrp{get;set;}
public String inti{get;set;}
public wrapClass(String agg
{
inti=agg;
system.debug('ssssssssss'+inti);
}
}
}

---------------------------------------------------------------------------------------------------------------------------

I am not sure as of why I am getting this error :  Unknown property 'String.inti' . Am I missing something?

 

 

 

Please help.

 

Cheers!!

Best Answer chosen by Admin (Salesforce Developers) 
ForcepowerForcepower

Adutt,

 

Remove or comment out your getWrp method as well since it is clashing with your loop variable:

 

/*
public String getWrp(){
return null;
}
*/

 

That should do it.

Best,

Ram

 

All Answers

paulo.orquillopaulo.orquillo

Your !wraplist call to the visualforce page is empty.

 

change it to 

<apex:dataTable value="{!result}" var="wrp" rendered="{!IF(count,true,false)}" border="1" >

 

 

then on your apex controller remove this code.

 

public String getWrapList() {
  return null ;
}

 

 

Cheers!

ForcepowerForcepower

Yes - good catch by Paulo. You have a couple of issues here:

 

1. A wrapList variable of type List<wrapList> but a String getWrapList()  getter which is bringing back a string rather than your wrapper class.

 

So you can do what Paulo said or just change the getWrapList method to this:

public list<wrapClass> getWrapList() {

    return wrapList;

}

 

 

2. You have a recursive definition in your wrapper class that I don't think you intend to have  - may want to remove it:

public class wrapClass{
//public wrapClass wrp{get;set;}
public String inti{get;set;}
public wrapClass(String agg
{
inti=agg;
system.debug('ssssssssss'+inti);
}
}

 

Hope that helps.

Ram

Bhawani SharmaBhawani Sharma
Looks like I just answered this in Visualforce Development section
AduttAdutt

Hi Ram, 

Thanks for the reply. based on your suggestion, i made the following changes to the code:

 

Page:

 

<apex:page controller="accountSearch">
<script>
function information()
{
method1();
alert('ddd');
var pbs1=true;
alert(pbs1);
}
</script>
<apex:form >
<apex:pageBlock >
<apex:outputLabel value="Enter your search text:" >
<apex:inputText value="{!searchVar}">
</apex:inputText>
</apex:outputLabel>
<apex:commandLink value="Search" action="{!getAccounts}" />


<apex:pageBlockTable value="{!accList}" var="acc" rendered="{!IF(count,true,false)}" >
<apex:column headerValue="Account Name">
<apex:commandLink action="{!getID}" value="{!acc.name}">
<apex:param name="var1" value="{!acc.id}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>

<apex:dataTable value="{!wrapList}" var="wrp" rendered="{!IF(count,true,false)}" border="1" >
<apex:column >
<apex:facet name="header">Count:</apex:facet>
<apex:outputText value="{!wrp.inti}"></apex:outputText>
</apex:column>
</apex:dataTable>

<apex:actionFunction name="method1" action="{!method1Action}"/>

<apex:pageBlockSection title="Account Information" rendered="{!IF(op1,true,false)}" collapsible="false" onclick="information()">
<apex:outputPanel rendered="{!IF(pbs1,true,false)}">
<apex:repeat value="{!selectedAccount}" var="selectedAcc" >
<td>
<tr>
<apex:pageBlockSection >
<apex:outputField value="{!selectedAcc.Name}"></apex:outputField>
</apex:pageBlockSection>
</tr>
</td>
</apex:repeat>

</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller:

 

public with sharing class accountSearch {


public String olId { get; set; }
public String searchVar { get; set; }
public String var;
public String var1{get;set;}
public Account selectedAccount{get;set;}
public list<Account> accList = new list<Account>();
public boolean op1=false;
public boolean pbs1=false;
public boolean count=false;
public list<wrapClass>wrapList = new list<wrapClass>();
public list<AggregateResult> agr = new list<AggregateResult>();

public PageReference getAccounts() {
var='%'+searchVar+'%';
system.debug('aaaaaaaaaaaa'+var);
accList = [Select id,name,NumberOfEmployees from account where name LIKE:var ];
system.debug('vvvvv'+accList);
count=true;
getResult();
system.debug('ddddddddddddddddd');
return null;
}

public list<wrapClass> getResult()
{
agr=[Select name,Count(id) quantity from Account where id IN : accList GROUP BY name ];
system.debug('ccccccccccc'+agr);
String str='';
for(AggregateResult a:agr)
{
str +=a.get('quantity');
system.debug('nnnnnnnn'+str);
wrapList.add(new wrapClass(str));
}
system.debug('rrrrrrrrrrr'+wrapList);
return wrapList;
}

public list<Account> getAccList(){
return accList;
}
public String getID()
{
String strId = apexpages.currentpage().getparameters().get('var1');
system.debug('lllllllllll'+strId);
selectedAccount=[Select name,OwnerId,Site,AccountSource,AnnualRevenue,NumberOfEmployees,Fax,Industry,Ownership,Phone,Rating,Type from Account
where id=:strId];
op1=true;
pbs1=false;
return null ;
}

public list<wrapClass> getWrapList() {
return wrapList;
}
public String getWrp(){
return null;
}
public Boolean getOp1()
{
return op1;
}

public void setOp1(Boolean abc)
{
this.op1=abc;
}
public Boolean getPbs1()
{
return pbs1;
}

public void setPbs1(Boolean abc)
{
this.pbs1=abc;
}
public void method1Action()
{
pbs1=true;
}
public Boolean getCount()
{
return count;
}

public void setcount(Boolean abc)
{
this.count=abc;
}

public class wrapClass{
public String inti{get;set;}
public wrapClass(String agg)
{
inti=agg;
system.debug('ssssssssss'+inti);
}
}}

-------------------------------------------------------------

 

But I am still getting the error : Unknown property 'String.inti' 

So not sure what to do...

AduttAdutt
Hi Paulo,
Thanks for the reply....
I tried with the changes you have mentioned, but still I am facing the same error.
ForcepowerForcepower

Adutt,

 

Remove or comment out your getWrp method as well since it is clashing with your loop variable:

 

/*
public String getWrp(){
return null;
}
*/

 

That should do it.

Best,

Ram

 

This was selected as the best answer
AduttAdutt

Hey Ram...

its working great except for a small change as mentioned by @Tech force

the final controller is :

public with sharing class accountSearch {


public String olId { get; set; }
public String searchVar { get; set; }
public String var;
public String var1{get;set;}
public Account selectedAccount{get;set;}
public list<Account> accList = new list<Account>();
public boolean op1=false;
public boolean pbs1=false;
public boolean count=false;
public list<wrapClass> wrapList{get;set;}
public list<AggregateResult> agr = new list<AggregateResult>();

public PageReference getAccounts() {
var='%'+searchVar+'%';
system.debug('aaaaaaaaaaaa'+var);
accList = [Select id,name,NumberOfEmployees from account where name LIKE:var ];
system.debug('vvvvv'+accList);
count=true;
getResult();
system.debug('ddddddddddddddddd');
return null;
}

public list<wrapClass> getResult()
{
agr=[Select name,Count(id) quantity from Account where id IN : accList GROUP BY name ];
system.debug('ccccccccccc'+agr);
String str='';
wrapList=new List<wrapClass>();
for(AggregateResult a:agr)
{
str +=a.get('quantity');
system.debug('nnnnnnnn'+str);
wrapList.add(new wrapClass(str));
}
system.debug('rrrrrrrrrrr'+wrapList);
return wrapList;
}

public list<Account> getAccList(){
return accList;
}
public String getID()
{
String strId = apexpages.currentpage().getparameters().get('var1');
system.debug('lllllllllll'+strId);
selectedAccount=[Select name,OwnerId,Site,AccountSource,AnnualRevenue,NumberOfEmployees,Fax,Industry,Ownership,Phone,Rating,Type from Account
where id=:strId];
op1=true;
pbs1=false;
return null ;
}

public list<wrapClass> getWrapList() {
return wrapList;
}

/*public String getWrp(){
return null;
}*/

public Boolean getOp1()
{
return op1;
}

public void setOp1(Boolean abc)
{
this.op1=abc;
}
public Boolean getPbs1()
{
return pbs1;
}

public void setPbs1(Boolean abc)
{
this.pbs1=abc;
}
public void method1Action()
{
pbs1=true;
}
public Boolean getCount()
{
return count;
}

public void setcount(Boolean abc)
{
this.count=abc;
}

public class wrapClass{

public String inti{get;set;}
public wrapClass(String agg)
{
inti=agg;
system.debug('ssssssssss'+inti);

}}}

ForcepowerForcepower

Adutt,

Glad to see you have it working.

Best,

Ram