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
Carl PierreCarl Pierre 

How to query an object picklist field?

I'm not able to query fields with picklist type

There is my query as example:
SELECT Landing_Page__c from Campaign
There is my error message
[
    {
        "message": "\nERROR at Row:1:Column:146\nNo such column 'Landing_Page__c' on entity 'Campaign'. 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.",
        "errorCode": "INVALID_FIELD"
    }
]
Best Answer chosen by Carl Pierre
Mahesh DMahesh D
Please check the permission for the user profile which your are using to connect the Salesforce.com.
Also if you added this field after you generate the WSDL then better to re-generate the WSDL.

Regards,
Mahesh

All Answers

venkat-Dvenkat-D
The query looks correct. Just check whether API name is correct or not.
Carl PierreCarl Pierre
Thanks for your response. The API name is correct

User-added image
 
venkat-Dvenkat-D
can you post your full code to investigate further
Carl PierreCarl Pierre


This is the file where I have my list of fields
<?php

return array(
    'fields' => array(
        'Id',
        'Name',
        'Owner.Name',
        'Channel__c',
        'Product__c',
        'Type',
        'Sub_Type__c',
        'Project__c',
        //'Objective__c',
        'Source__c',
        'Account_BizDev__c',
        'Tactic__c',
        'Target_Audience__c',
        'Landing_Page__c',
        'CID_Placement__c',
        'Content_Type__c',
        'Content__c',
        'Contract_Type__c',
        'City__c',
        'State__c',
        'Region__c',
        'Country__c',
        'PPC_Campaign__c',
        'Ad_Group__c',
        'Keyword__c',
        'Match_Type__c',
        'Campaign_ID_18_digit__c',
    ),
);


The code used to pull the campaigns
public function getCampaigns($instance_url, $access_token) {
        $qfields = implode(', ', $this->fields); /// fields listed in the previous array
        $query = "SELECT $qfields from Campaign";
        
        $url = "$instance_url/services/data/v20.0/query?q=" . urlencode($query);

        return $this->execute($url, NULL, $access_token);
 }


The execute function
private function execute($url, $params = null, $access_token = null) {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: OAuth $access_token"));
$json_response = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ($status != 200) {
            die("Error: status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
        }

        curl_close($curl);

        return json_decode($json_response, TRUE);
}





 
venkat-Dvenkat-D
Remove , at the end of last field campaign 18 I'd.
Carl PierreCarl Pierre


This is my print of my entire php query

 

SELECT Id, Name, Owner.Name, Channel__c, Product__c, Type, Sub_Type__c, Project__c, Source__c, Account_BizDev__c, Tactic__c, Target_Audience__c, Landing_Page__c, CID_Placement__c, Content_Type__c, Content__c, Contract_Type__c, City__c, State__c, Region__c, Country__c, PPC_Campaign__c, Ad_Group__c, Keyword__c, Match_Type__c, Campaign_digit__c from Campaign"

if I remove Landing_Page__c it works
 
Mahesh DMahesh D
Please check the permission for the user profile which your are using to connect the Salesforce.com.
Also if you added this field after you generate the WSDL then better to re-generate the WSDL.

Regards,
Mahesh
This was selected as the best answer
venkat-Dvenkat-D
I agree with Mahesh check for Field level security for the user which is used in php. Once required access is given you can check again
Carl PierreCarl Pierre
Ok thanks guys I will try this solution and keep you posted
Carl PierreCarl Pierre
Thanks
Carl PierreCarl Pierre
it was security field