connected apps – Query (SOQL) on connectedApplication to get clientId and clientSecreet
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;
Read more here: Source link