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
Shazib MahmoodShazib Mahmood 

Tooling API query not working for non system administrator

Hello,

In order to grab custom field IDs, I added a tooling API query. Any profile without "View All Data" gets the following response for HTTP Request.
The standard profile does have API enabled permission and full CRED access on any involved object. The Apex class has "Without Sharing" tag as well.

CALLOUT_RESPONSE|[58]|System.HttpResponse[Status=Bad Request, StatusCode=400]

Sample Code:
 
String query = 'SELECT Id From CustomObject Where DeveloperName = \'' + objectName + '\'';
        String endpoint = Url.getSalesforceBaseUrl().toExternalForm();
        endpoint += '/services/data/v29.0/tooling/query/?q=';
        endpoint += EncodingUtil.urlEncode(query, 'UTF-8');
        
        HttpRequest request = new HttpRequest();
        request.setMethod('GET');
        request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());

I need to either:

1. Adjust the non-system admin profile, so that its SessionId gets a proper response like a profile with "View All Data" e.g system admin.
2. Somehow use a sessionId that doesnt belong to current session's profile holder. Use a system admin's sessionid WITHOUT embedding their username and password anywhere.
3. Get further debugging information from the HTTP response. I am not really sure about the specifics of why its a "bad request".


Any guidance would be appreciated. Thanks
Best Answer chosen by Shazib Mahmood
Daniel BallingerDaniel Ballinger
According to Describe call to sobjects with Tooling API fails (http://salesforce.stackexchange.com/a/88949/102) the consensus seems to be that you need the "View All Data" permission to work with the Tooling API.

All Answers

Daniel BallingerDaniel Ballinger
Note the following from the CustomObject (https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_customobject.htm?search_text=CustomObject) documentation:
Available from API version 31.0 or later.
Try updating your URL to use the latest Spring '16 release:
endpoint += '/services/data/v36.0/tooling/query/?q=';




 
Shazib MahmoodShazib Mahmood
Thanks for the reply but unfortunately changing the API version doesn’t help much.
Daniel BallingerDaniel Ballinger
According to Describe call to sobjects with Tooling API fails (http://salesforce.stackexchange.com/a/88949/102) the consensus seems to be that you need the "View All Data" permission to work with the Tooling API.
This was selected as the best answer
Lucas CalegariLucas Calegari
I was able to get it with:
 
String objectName = 'Account';
        
        // To work with Tooling API : View All Data Permission
        String query = 'SELECT Id, Active, Description, ErrorMessage From ValidationRule Where EntityDefinition.DeveloperName = \'' + objectName + '\'';
        
        String endpoint = Url.getSalesforceBaseUrl().toExternalForm();
        endpoint += '/services/data/v41.0/tooling/query/?q=';
        endpoint += EncodingUtil.urlEncode(query, 'UTF-8');
            
        Http http = new Http();
        HttpRequest httpReq = new HttpRequest();
        HttpResponse httpRes = new HttpResponse();
        
        httpReq.setMethod('GET');
        httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId()); 
        httpReq.setEndpoint(  endpoint );

 
Ali Raza 35Ali Raza 35
William lee 52William lee 52

Thanks for sharing amazing post

mobile mechanic reading (https://smartservicingcentre.co.uk)

nani rocknani rock
This is a very good website and informative article. You give the tips to read every newbie like me and also inspiring to me. I’m Following, Thank you For sharing This Knowledge.
celebritiesdata (https://celebritiesdata.com/)
josef zeejosef zee

Thanks for sharing 

https://etisalatspeedtest.site (https://etisalatspeedtest.site/)

https://speed.ptclbill.info/ptcl-speed-test (https://speed.ptclbill.info/ptcl-speed-test/)

chaudhary asadchaudhary asad
Thanks for sharing amazing post
airtel balance check (https://mybalancetoday.com)
airtel ussd codes (https://mybalancetoday.com/airtel-ussd-codes)
Alex Taylor 34Alex Taylor 34