0

I am creating a connected app through metadataservice. But i am not able to retrieve the clientId and clientSecret from this newly created connected app in apex class

2
  • why would you expect there be API access to a clientSecret?
    – cropredy
    Commented Oct 11, 2023 at 17:05
  • I need to send these details back to the external system once the connected app is created upon their request Commented Oct 12, 2023 at 4:18

2 Answers 2

0

I found the solution. You can use "readMetadata" method from "Metadataservice" class to retrieve the consumerKey.

https://github.com/certinia/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls

-1

it is not possible to retrieve the client_id and client_secret for a connected app directly within Apex in Salesforce. The client_id and client_secret are sensitive information and should be kept secure. In Salesforce, these values are typically generated when you create a connected app through the Salesforce Setup menu.

If you still wanna to retrieve client_id and client_secret, you can use custom metadata. Create a custom metadata and store the client_id and client_secret on it. And use it in apex like:

CustomMetadataRecord__mdt customMetadata= CustomMetadataRecord__mdt.getInstance('customMetadataRecordName'); String clientId = (String)myMetadata.Client_Id__c; String clientSecret = (String)myMetadata.Client_Secret__c;

2
  • I have created a REST resource that will be accessed by an external system to create a connected app. Once the connected app is created, I want to send this information back. Can you suggest a way to achieve this besides using custom metadata? Commented Oct 12, 2023 at 4:22
  • No others way to get client_id and client_secret dynamically.
    – Raj
    Commented Oct 13, 2023 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .