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
Gorilla ToolzGorilla Toolz 

SOQL Works in Developer Console but not in API

 The following SOQL executes successfully in the Force.com developer console, but not through the API using the Partner WSDL.   I am logging in as the same user to the API as I use for the developer console (same user, System Administrator profile).


SELECT OpportunityId, Id, PricebookEntryId, Product2.Name, ProductCode, Quantity, UnitPrice, Description, LastModifiedDate, IsDeleted FROM OpportunityLineItem LIMIT 5

I'm using the SOAP 31.0 api and getting the following error:

First I got an error on the Product2.Name, removed that from the SOQL and got an error on the ProductCode:

No such column 'ProductCode' on entity 'OpportunityLineItem'. 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.

The API worked fine with the same SOQL accessing test.salesforce.com, but not login.salesforce.com.

I looked in to field level security, but I am using the same user account/system admin profile for both developer console and api. 

Appreciate any guidance you can provide.
Best Answer chosen by Gorilla Toolz
Vijaya Kumar RegantiVijaya Kumar Reganti
Hi,

You can not access the product2 fields directly from the OpportunityLineItem.you have to go through the PriceBookEntry. 

Use priceBookEntry.product2.productcode 

This will work.

Thanks,
Vijay 

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
I tried the same query in both developer console and Apex code and it's fine for me. 

If you are trying to create to access some custom Opportunitylineitem then please chech if there is any pricebook entried define for that.

Vijaya Kumar RegantiVijaya Kumar Reganti
Hi,

You can not access the product2 fields directly from the OpportunityLineItem.you have to go through the PriceBookEntry. 

Use priceBookEntry.product2.productcode 

This will work.

Thanks,
Vijay 
This was selected as the best answer
Gorilla ToolzGorilla Toolz
Thanks Vijay, I will use that as a work-around.