+ Start a Discussion
shephalishephali 

Error: Compile Error: Illegal assignment from List<AggregateResult> to List<Contact_Agent__c> public class Verify { public list<Code> C{set;get;} public Verify() { C=[select MAX(Code__c) from Contact_Agent__c]; } } how to correct it?

Error: Compile Error: Illegal assignment from List<AggregateResult> to List<Contact_Agent__c>   
public class Verify {
 public list<Code> C{set;get;}  
  public Verify()
    {  C=[select MAX(Code__c) from Contact_Agent__c];}
}
how to correct it???
Best Answer chosen by shephali
RAM AnisettiRAM Anisetti
Hey,

MAX(Code__c) will return single value not bulk...so no need to use "pageblocktable",simply use <apex:outputtext>

<apex:page controller="Verify" sidebar="false">
  <apex:form >
        <apex:pageBlock >
        
        Max Value is :  <apex:outputText value="{!c}" ></apex:outputText>
        
    </apex:pageblock>
    </apex:form>
</apex:page>

+++++++++++++++++++++++++++++++++++++++++++++++++



public class Verify {

public Object  C{set;get;}  

public Verify(){
AggregateResult[] groupedResults = [select MAX(Code__c)maxvalue from Contact_Agent__c];

c= groupedResults[0].get('maxvalue');
}
}







 

All Answers

RAM AnisettiRAM Anisetti
Hi swarnkar 9,

modify your code like below....

public class Verify {

public Object  C{set;get;}  

public Verify(){
AggregateResult[] groupedResults = [select MAX(Code__c)maxvalue from Contact_Agent__c];

Object c= groupedResults[0].get('maxvalue');
}
}
shephalishephali
Hi RAM,
   Thanks for Your reply.here now I am unable to fetch this object to VF page.
shephalishephali
Hello Ram,
     I am getting this error.
                 Error: Unknown property 'Object.Code__c'
RAM AnisettiRAM Anisetti
hi,
provide me vf code also...
shephalishephali
Hi,
here is the vf code with error.
 Error: Unknown property 'Object.Code__c'
<apex:page controller="Verify" sidebar="false">
  <apex:form >
        <apex:pageBlock>
        <apex:pageblocktable value="{!Code}" var="c"> 
            <apex:column value="{!c.Code__c}"/>
             </apex:pageblocktable>
    </apex:pageblock>
    </apex:form>
</apex:page>
RAM AnisettiRAM Anisetti
Hey,

MAX(Code__c) will return single value not bulk...so no need to use "pageblocktable",simply use <apex:outputtext>

<apex:page controller="Verify" sidebar="false">
  <apex:form >
        <apex:pageBlock >
        
        Max Value is :  <apex:outputText value="{!c}" ></apex:outputText>
        
    </apex:pageblock>
    </apex:form>
</apex:page>

+++++++++++++++++++++++++++++++++++++++++++++++++



public class Verify {

public Object  C{set;get;}  

public Verify(){
AggregateResult[] groupedResults = [select MAX(Code__c)maxvalue from Contact_Agent__c];

c= groupedResults[0].get('maxvalue');
}
}







 
This was selected as the best answer
shephalishephali
Thank you RAM!!!
It is working....:)