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 Answers
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
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;
-
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
-