0

I am unable to retrieve the Certificates of an org using the Financial Force Metadata API Apex Wrapper although I see the object in the Metadata API Documentation and can query it using the workbench.

When I call:

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();  

MetadataService.ListMetadataQuery query = new MetadataService.ListMetadataQuery();
query.type_x = 'Certificate';

for(MetadataService.FileProperties prop : service.listMetadata(new List<MetadataService.ListMetadataQuery>{ query }, 25)) {
    System.debug(prop.fullName);
}

I get:

Line: 13524, Column: 1 System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_TYPE: Cannot use: Certificate in this version faultcode=sf:INVALID_TYPE faultactor=

I also tried "certs", "cert", "certificates" for query.type_x.

Note: this is breaking down my issues of Create Certificate/SSO Config in Apex using Metadata API into multiple questions as I didn't get any helpful feedback there.

0

I was able to query the Certificates using the Tooling API instead:

HttpRequest request = new HttpRequest();
request.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + '/services/data/v46.0/tooling/query?q=Select+Id,DeveloperName+FROM+' +  type);
request.setMethod('GET');
request.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
request.setHeader('Content-Type', 'application/json');

ToolinApiResponse response = (ToolinApiResponse)
                                JSON.deserialize(new Http().send(request).getBody(), ToolinApiResponse.class);

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.