6

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.
  • Does it work for another custom object ? – Devendra Jul 26 '16 at 18:37
  • 1
    try also by logging in as this user to SFDC Workbench to see if there is access – cropredy Jul 26 '16 at 23:55
  • @cropredy It worked in workbench. I have added more details on the case; please check. – RajeshShah Jul 27 '16 at 5:04
  • 5
    Any reason in particular you're using API version 8 on the SOAP url? Does it make a difference if you update that to 23 or later? https://login.salesforce.com/services/Soap/u/37.0 – Mark Pond Aug 5 '16 at 0:46
  • 4
    Holy crap, I didn't even know there was an API Version 8.0. @MarkPond – Adrian Larson Aug 5 '16 at 16:06
6
+25

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.

| improve this answer | |
  • I will check on the part about Constants.pm. Regarding the API not having access to the object, I logged in as the API user in Salesforce and was able to view a record of that object. There is also no namespace that we have defined. – RajeshShah Aug 5 '16 at 5:23
  • Can you see the raw api call that is getting made. – Daniel Ballinger Aug 5 '16 at 6:47
  • I am checking with my integration team on this. Will update soon. – RajeshShah Aug 5 '16 at 7:58
  • Heres what we have found: Constants.pm doesn't list all the custom objects that get_tables() show. For e.g., we have a custom object Daily_Usage__c which is not constants.pm but the query on that works fine. ContractAsset__c is not in their but the query on it doesn't work. – RajeshShah Aug 5 '16 at 8:25
2

Looks like the module uses partner wsdl to get Salesforce metadata information. --Edit-- Please follow this solution

| improve this answer | |
  • 2
    The Enterprise WSDL isn't required to get custom objects. It is strongly typed where as the Partner API is dynamic. – Daniel Ballinger Jul 26 '16 at 23:53
  • see help.salesforce.com/apex/… – cropredy Jul 26 '16 at 23:54
  • It is able to query 1 custom object but not 2 others. – RajeshShah Jul 27 '16 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.