[SalesForce] API unable to query Custom Object inspite of required permission

We have an API integration which uses the Salesforce cpan module to query data from Salesforce. This module uses the API version 23.0. It works fine when it queries on objects like Account, Contract and Asset. We recently created a new object called ContractAsset which is a junction object between Contract and Asset. The API Profile for this user has Read, Edit and Create permission for this object. The query for this object doesn't work and throws the following error:

INVALID_TYPE: sObject type \'ContractAsset__c\' is not supported.

Below is the query:

SELECT zAsset__c, zContract__r.Support_Code__c FROM ContractAsset__c WHERE zAsset__r.SerialNumber = 'ABCD'

What might be the reason for this? Any suggestions? Below are some connection parameters been used.

$SF_PROXY       = 'https://login.salesforce.com/services/Soap/u/8.0';
$SF_URI         = 'urn:partner.soap.sforce.com';
$SF_PREFIX      = 'sforce';
$SF_SOBJECT_URI = 'urn:sobject.partner.soap.sforce.com';
$SF_URIM        = 'http://soap.sforce.com/2006/04/metadata';
$SF_APIVERSION  = '23.0';

Edit

Here are few more details on what we have tried:

  • I am able to query the object via Workbench. I even tried using the API version 23 of workbench for this.
  • This integration has been live for the past 2 years. It is able to query the custom object that was created before the integration started but is unable to query 2 custom objects created after the integration was live. Of course, I haven't tested every custom object but the fact that it is able to query 1 custom object and not the 2 others made me infer this fact.

Best Answer

Have you recently registered a namespace prefix in the Org your are running the SOQL query against? If so, you will need to add the prefix to all custom object and field names.

E.g.

SELECT abc__zAsset__c, abc__zContract__r.abc__Support_Code__c
FROM abc__ContractAsset__c
WHERE abc__zAsset__r.SerialNumber = 'ABCD'


Otherwise, from the CPAN project page you linked to I found my way over to a Github repo p5-salesforce/WWW-Salesforce. It's been many years since I've attempted anything with Perl.

I did find Constants.pm. What is really weird about that file is it has a number of custom objects and fields defined in it. E.g.

        'customobject1__c' => {
            'contact__c'       => 'xsd:string',
            'createdbyid'      => 'xsd:string',
            'createddate'      => 'xsd:dateTime',
            'field1__c'        => 'xsd:string',
            'lastmodifiedbyid' => 'xsd:string',
            'lastmodifieddate' => 'xsd:dateTime',
            'lead__c'          => 'xsd:string',
            'name'             => 'xsd:string',
            'ownerid'          => 'xsd:string',
            'systemmodstamp'   => 'xsd:dateTime',
        },
        'customer__c' => {
            'createdbyid'      => 'xsd:string',
            'createddate'      => 'xsd:dateTime',
            'lastmodifiedbyid' => 'xsd:string',
            'lastmodifieddate' => 'xsd:dateTime',
            'name'             => 'xsd:string',
            'ownerid'          => 'xsd:string',
            'systemmodstamp'   => 'xsd:dateTime',
        }

Perhaps you need to add any additional custom objects you want to use in that file?

That said, the error message you are getting back appears to be a standard Salesforce response when they API user doesn't have access to the sObject in question or it out right doesn't exist. I'd expect the full message to be more like:

INVALID_TYPE: 
zContract__r.Support_Code__c FROM ContractAsset__c WHERE zAsset__r.SerialNumber
                                  ^
ERROR at Row:1:Column:53
sObject type 'ContractAsset__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.
Full Query: SELECT zAsset__c, zContract__r.Support_Code__c FROM ContractAsset__c WHERE zAsset__r.SerialNumber = 'ABCD'

Double check that the API user that is making the call has access to the custom objects you are querying.