How can we read BYOK Compatible certificates present in Salesfoce using Apex (or SF REST APIs). Also is there any way to generate BYOK Compatible certificate using Apex code or SF REST APIs.

I referred below link but it only talks about creating tenant secret using REST api.



I am able to fetch other metadata like "ApexClass" using below code. However, for certificate getting error INVALID_TYPE. (using package mentioned by Chuck: https://github.com/financialforcedev/apex-mdapi)

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

List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();                  
MetadataService.ListMetadataQuery queryWorkflow = new MetadataService.ListMetadataQuery();

queryWorkflow.type_x = 'ApexClass'; //working
//queryWorkflow.type_x = Certificate//not working


MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);

for(MetadataService.FileProperties fileProperty : fileProperties) {

Managing the cert can be done via the MetaData API: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_certificate.htm

There isn't a straightforward way to do that with Apex. You might be able to hack it out using the FinancialForce package: https://github.com/financialforcedev/apex-mdapi

  • Thanks Chuck for reply. I tried with examples mentioned by you. However, I am not able to query 'Certificate' info (getting error INVALID_TYPE), but other type are working fine (eg: ApexClass) and I am able to query them. – Neeraj Kukreti Apr 9 '18 at 3:22
  • @NeerajKukreti If you are trying to SOQL query, Certificate is not considered as an SObject type, unlike ApexClass. Chuck's point is that the data is technically accessible through an API, but not native to Apex. – TheSFDCTower Apr 12 '18 at 4:28
  • @TheSFDCTower I am using FinancialForce package mentioned by Chuck but still not able to fetch certificate info. I have updated my question with snippet I am using. – Neeraj Kukreti Apr 19 '18 at 6:33

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.