3

I want to view the Metadata(RecordType, VF access, Apex class access,etc.) from Profile using Tooling API. My code looks similar to this

ToolingAPI toolingAPI = new ToolingAPI();
List<ToolingAPIWSDL.sObject_x> profileObject =    (List<ToolingAPIWSDL.sObject_x>)toolingAPI.query('Select Description, FullName,     Metadata From Profile Where FullName = \'Admin\'').records;
System.debug('Description' + profileObject.Description);
System.debug('FullName' + profileObject.FullName);
System.debug('Metadata' + profileObject.Metadata);
System.debug('RT' + profileObject.Metadata.ProfileRecordTypeVisibility);
System.debug('VF' + profileObject.Metadata.ProfileApexPageAccess );

By this code i can see in the debug description, fullname correctly stated, but metadata receive null values for all fields like ProfileRecordTypeVisibility, ProfileApexPageAccess, etc. Where could be the problem? How can I get any list for record types, apex classes, pages for any profile?

1

I do not have experience with the Tooling API querying Profiles but I know in the MetaData API you must specify the object as well as the profile to return object and field permissions. It appears to be the case that the Tooling API has the same issue.

An alternative (linked to below) is to simply query the permissions objects, as defined here: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_permissionset.htm

For example:

SELECT Id
FROM ObjectPermissions
WHERE SobjectType = 'Merchandise__c'

For more information see this similar question: Tooling API - ProfileMetadata not being returned v32

  • But I want to list of Apex Classes, Pages and Record Types for particular profile that I choose. – Daniel Oct 19 '16 at 10:07
0

The data is coming back in the SOAP response. It will just be a matter of getting the backing Apex classes correct to deserialize the response.

toolingSoapSforceCom.SforceService toolingAPI = new toolingSoapSforceCom.SforceService();
toolingAPI.SessionHeader = new toolingSoapSforceCom.SessionHeader_element();
toolingAPI.SessionHeader.SessionId = UserInfo.getSessionId();
toolingAPI.endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/T/36.0';

toolingSoapSforceCom.sObject_x[] profileObjects =  toolingAPI.query('Select Description,  Metadata From Profile Where Id = \'00e70000000sye7AAA\'').records;
for(toolingSoapSforceCom.sObject_x profile : profileObjects) {
    System.debug(profile);
}

CALLOUT_RESPONSE:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:tooling.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mns="urn:metadata.tooling.soap.sforce.com">
  <soapenv:Body>
    <queryResponse>
      <result>
        <done>true</done>
        <entityTypeName>Profile</entityTypeName>
        <queryLocator xsi:nil="true" />
        <records xsi:type="Profile">
          <Id xsi:nil="true" />
          <Metadata>
            <mns:custom>false</mns:custom>
            <mns:userLicense>Salesforce</mns:userLicense>
            <mns:userPermissions>
              <mns:enabled>false</mns:enabled>
              <mns:name>AccessCMC</mns:name>
            </mns:userPermissions>
            <mns:userPermissions>
              <mns:enabled>true</mns:enabled>
              <mns:name>ActivateContract</mns:name>
            </mns:userPermissions>
            <!-- ... -->
          </Metadata>
        </records>
        <size>1</size>
        <totalSize>1</totalSize>
      </result>
    </queryResponse>
  </soapenv:Body>
</soapenv:Envelope>

Check your API version. Salesforce has been changing the namespaces in the recent couple of releases of the Tooling API. See Knowledge Article 206845 - Spring 15 - Tooling API changes

  • SessionId and endpoint is set in ToolingAPI.cls and I am using API version 36.0. When I debug Metadata they look like: – Daniel Oct 20 '16 at 6:43
  • MetadataMetadata:[recordTypeVisibilities=null, recordTypeVisibilities=null, recordTypeVisibilities_type_info=(recordTypeVisibilities, urn:metadata.tooling.soap.sforce.com, null, 0, -1, false), classAccesses=null, classAccesses_type_info=(classAccesses, urn:metadata.tooling.soap.sforce.com, null, 0, -1, false) ..... and the same for all fields – Daniel Oct 20 '16 at 6:46
  • Where did you get your ToolingAPI.cls from? Did you generate it? It should contain a class that represents the Metadata. – Daniel Ballinger Oct 20 '16 at 6:49
  • it was added from github github.com/afawcett/apex-toolingapi . It contains ToolingApi.cls, ToolingAPIWSDL, ToolingAPIWSDLMetadata, ToolingAPIWSDLMock, and test classes. – Daniel Oct 20 '16 at 8:19
  • I am sorry, we used API version of 29 for Tooling API, so i will probably try to get newer one and probably it will fix my issue. I will let you know. – Daniel Oct 20 '16 at 11:22

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.