You need to sign in to do that
Don't have an account?
ckellie
Invalid field CampaignName__c for AggregateResult
I am using the aggregatere result function to a second, dependant picklist and am trying to assign the second picklist to the recorrd. I am trying to attach the aggregated result value to a mapping value.
Here is the error message:
System.SObjectException: Invalid field CampaignName__c for AggregateResult Class.CampaignListOwner7.getcampaignlists: line 61, column 35 External entry point
Class code:
public with sharing class CampaignListOwner7{ List<SelectOption> selectedOwnerList = new List<SelectOption>(); Map<id, String> mappingval = new Map<id, String>(); Map<id, String> mappingcval = new Map<id, String>(); public String selectedval { get; set;} public String selectedcval { get; set;} public String cval { get; set;} public CampaignListOwner7(ApexPages.StandardController controller) { } public String getCampaign() { return this.Campaign; } public String getCampaignStatus() { return this.CampaignStatus; } public string s; public String campaign; public string campaignstatus; public transient string Campaignid{ get; set;} private transient CampaignMember[] members; //the members for that campaign public transient String owner; //owner ID public string getOwner() { return this.owner; } public void setOwner(String s) { this.Owner = s; } public List<CampaignMember> CampaignMember { get; set;} public List<SelectOption> getselectedOwner(){ List<SelectOption> optionList = new List<SelectOption>(); optionList.add(new SelectOption( '1', 'SELECT' )); for(User u:[select id,name from user where id in (select ownername__c from campaignmember) order by name]) { optionList.add(new SelectOption(u.id, u.name)); mappingval.put(u.id, u.name); } return optionList; } public List <SelectOption> getcampaignlists(){ system.debug('SFDC TEST ************ OWNER' + Owner); AggregateResult[]groupedResults = [select Campaign_Name__c from campaignmember where ownername__c=:selectedval group by Campaign_Name__c]; List <SelectOption> optionList = new list<SelectOption>(); optionList.add(new SelectOption( '1', 'SELECT' )); system.debug('SFDC TEST *************' + selectedVal); if(selectedval!= null){ for(Aggregateresult ar :groupedResults) { optionList.add(new SelectOption(String.valueof( ar.get('Campaign_Name__c')), String.valueof(ar.get('Campaign_Name__c')))); String aID = (string)ar.get('Campaign_Name__c'); String abID = (string)ar.get('CampaignName__c'); mappingcval.put(abID, aID); } } return optionList; } public PageReference campaignRefresh() { system.debug('$$$$$:'+selectedval); system.debug(mappingval.get(selectedval)); try { if(selectedval != null) { CampaignMember = [select Id, owner_Name__c, CurrencyIsoCode, status from Campaignmember where owner_Name__c =: mappingval.get(selectedval)limit 99]; }else CampaignMember = [select Id, owner_Name__c, Campaign_Name__c, status, CurrencyIsoCode from Campaignmember where owner_Name__c =: mappingval.get(selectedval) and Campaign_Name__c =: mappingcval.get(selectedcval) limit 99]; }catch( Exception e ){ ApexPages.addMessages( e ); } system.debug('##################' + CampaignMember); return null; } }
How do I put the aggregate result to the mappingcval?
Thank you
Thank yoyu for your help Anit. The below has solved my error:
All Answers
The problem is here :
You are fetching "CampaignName__c" from aggregate result without querying it in aggregate query.
Just change your query like this :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Thank you for your reply.
I have replaced the code as recommended
and recieve the following error:
I have tried to group by both fields
and recieve the following visualforce error
Campaign_Name__c is a text field and CampaignName__c is a formula field.
Not sure as these fields are your custom fields and don't even know the data type of them. So lets go with the error
Try this :
You are not using any aggregate function, that might be a problem. Worth a shot.
Let me know if you still face any problem.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Thank you for the code, but this code:
Is returning the following error:
Try any of the below, whichever suits you :
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Thank yoyu for your help Anit. The below has solved my error:
How you got "groupedResults".
select count(Id),AccountId from case where Case.IsClosed = false GROUP BY AccountId
throwing error:
(279728000)|EXCEPTION_THROWN|[11]|System.UnexpectedException: Field must be grouped or aggregated: AccountId
I have morphed this code since the solution and here is the final code I am using:
Hope this helps you.
Hi all ,
iam getting the following error in soql query.can any one please help me out
here is the code
public class ag1
{
public integer Ont1{get;set;}
public integer T1{get;set;}
public string s1{get;set;}
public list<AggregateResult> lstar=new list<AggregateResult>();
public ag1()
{
lstar=[select count(id),sum(OnTherapyCurrWk__c) s1,sum(TreatmentGapCurrWk__c)s2,sum(OrderPendingCurrWk__c)s3,sum(EIPCurrWk__c)s4,sum(PreStartCurrWk__c)s5,ProductID__c from ProdTerrData__c group by ProductID__c];
}
public list<OppClass> getResults()
{
list<OppClass> lstResult = new list<OppClass>();
for (AggregateResult ar: lstar)
{
oppClass objOppClass = new oppClass(ar);
lstResult.add(objOppClass);
}
return lstResult;
}
class oppClass
{
public integer onterapaycurrwk { get;set; }
public integer TreatmentGapCurrWk { get;set; }
public integer OrderPendingCurrWk{get;set;}
public integer EIPCurrWk{get;set;}
public integer PreStartCurrWk{get;set;}
public oppClass(AggregateResult ar)
{
onterapaycurrwk =integer.valueOf(ar.get('s1'));
TreatmentGapCurrWk = integer.valueOf(ar.get('s2'));
OrderPendingCurrWk=integer.valueof(ar.get('s3'));
EIPCurrWk=integer.valueof(ar.get('s4'));
PreStartCurrWk=integer.valueof(ar.get('s5'));
}
}
}