+ Start a Discussion
sparkysparky 

SOQL on CampaignMemberStatus fails in apex class?

Not sure if this is a bug or my error, I of course assume the latter until proven guilty.

I've got an apex class I'm building in eclipse.  Not much going on yet, here's what it looks like so far:

Code:
Public Class CampaignMemberStat{

 Public Static string GetRespondedStatus (Id campId) {
 
 // for a given campaign, look up the 'default' status to use for Responded
 
  CampaignMemberStatus[] cStatus = [Select c.Label, c.IsDefault From CampaignMemberStatus c WHERE c.CampaignId = :campId ORDER BY c.HasResponded desc, c.IsDefault desc]; 

 }

}
When I attempt to compile this, i get an error "Illegal assignment from LIST:SOBJECT:CampaignMemberStatus to LIST:CampaignMemberStatus" on the line w/ the SOQL.  I've checked and don't see anything wrong w/ my syntax.  It's also true that:
 

* the SOQL query works in testing if I replace the variable w/ an Id
* the line as written seems to compile if pasted into a trigger (not a class)
* the class as written compiles if I chg the line into a query on another object (like Contact) instead of CampaignMemberStatus

Is there some restriction to using CampaignMemberStatus in a class?  Or did I just screw up somewhere?

Thanks!
SuperfellSuperfell
You have an apex class somewhere that's visible to that code that's also called CampaignMemberStatus, that'll take precendce in the name scope search, so CampanignMemeberStatus [] becomes an array of your apex class, and not the system defined CampaignMemberStatus class. try System.CampaignMemberStatus [] for your variable instead.
sparkysparky
Thanks, Simon!  That did the trick.

I had originally thought of that, had named the class w/ a reserved word to start.  But then I renamed it via eclipse and figured that couldn't be the problem after that.  But turns out the eclipse rename function does not in fact rename the code class in SFDC.   So the problem still existed.

So I guess you need to physically remove the class, then recreate it w/ the new name?

I've also sinced upgraded my apex toolkit to the latest version, so maybe that was the problem.
AltiumForceAltiumForce

I've made same mistake.

LOL