+ Start a Discussion
S2S CRM AdminS2S CRM Admin 

Get the FirstName from the CampaignMember Object

I am attempting to create a select statement that will pull all the first names of members that are signed up to a specific campaign. I am relatively new to using the Salesforce API so I decided to simplify it and just try to pull the first name of any member of any campaign. I wrote the following code:
SELECT FirstName FROM CampaignMember
When I run the statement I recieve the following error:
PHP Fatal error:  Uncaught SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: 
SELECT FirstName FROM CampaignMember
       ^
ERROR at Row:1:Column:8
No such column 'FirstName' on entity 'CampaignMember'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. in C:\Sites\s2s\htdocs\salesForce\soapclient\SforceBaseClient.php:808
Stack trace:
#0 C:\Sites\s2s\htdocs\salesForce\soapclient\SforceBaseClient.php(808): SoapClient->__call('query', Array)
#1 C:\Sites\s2s\htdocs\salesForce\soapclient\SforceBaseClient.php(808): SforceSoapClient->query(Array)
#2 C:\Sites\s2s\htdocs\test.php(28): SforceBaseClient->query('SELECT FirstNam...')
#3 {main}
  thrown in C:\Sites\s2s\htdocs\salesForce\soapclient\SforceBaseClient.php on line 808

I did confirm that all user profiles are allowed to view the CampaignMember object. From what research I have done I discovered that Salesforce use to have this bug. Has this been patched out, or is there another reason I am recieving the error? 
 
Yury BondarauYury Bondarau
Hi,

Actually, CampaignMember information coming from Lead or Contact objects, so can you try the following code:
 
SELECT Id, Contact.FirstName, Lead.FirstName FROM CampaignMember
Here we try to get FirstName directly from parent object (Lead or Contact)
S2S CRM AdminS2S CRM Admin
Hello Yury,

Thanks to your help I am now half way there. If I use the following statement in the developers console I get a successful result, but when I run it from my external php page I get the following errors.

Statement:
SELECT Contact.FirstName, Contact.Title FROM CampaignMember WHERE CampaignId='701i00000010q96'

Error Messages that I recieve when I run the code from my php page:
PHP Notice:  Undefined variable: record in C:\Sites\s2s\htdocs\tech_demo\salesForce\soapclient\SforceBaseClient.php on line 973
PHP Notice:  Trying to get property of non-object in C:\Sites\s2s\htdocs\tech_demo\test.php on line 34
PHP Notice:  Trying to get property of non-object in C:\Sites\s2s\htdocs\tech_demo\test.php on line 34
PHP Notice:  Trying to get property of non-object in C:\Sites\s2s\htdocs\tech_demo\test.php on line 35
PHP Notice:  Trying to get property of non-object in C:\Sites\s2s\htdocs\tech_demo\test.php on line 35
PHP Notice:  Trying to get property of non-object in C:\Sites\s2s\htdocs\tech_demo\test.php on line 36
PHP Notice:  Trying to get property of non-object in C:\Sites\s2s\htdocs\tech_demo\test.php on line 36