I have created connected App using metadata API,Now I have to retrieve connected App's Information using metadata API,The code is working fine for the Apps which is created manually but not for the Apps which is created through metadata .I have provided full access for both connected Apps.

public static void retrieveConnectedApp() {
    MetadataService.MetadataPort service = new MetadataService.MetadataPort();
    service.SessionHeader = new MetadataService.SessionHeader_element();
    service.SessionHeader.sessionId = UserInfo.getSessionId();
    MetadataService.ConnectedApp connectedApp =
            (MetadataService.ConnectedApp)service.readMetadata('ConnectedApp', new String[] {'ActivePrime' }).getRecords()[0];

Is there any security issue ? For Oauth authentication, connected app (manually) is working fine but connected app (Metadata API) failed .

  • Have you define profile settings (objects accessible through connected App) for users which will be accessing data? Feb 16, 2017 at 8:55
  • Connected App is not an object itself . what profile setting I am supposed to do? Feb 16, 2017 at 10:30
  • I've already answered this question. Please visit this link Feb 16, 2017 at 10:31
  • I just went through given link . So where I can provide those permissions ? Feb 16, 2017 at 11:26
  • @AjayPrakashDubey, so a Connected App that you created in the UI is coming back with that Apex code, but not one that you created via the Metadata API? Are there any errors, or is the latter just not returning a MetadataService.ConnectedApp? Feb 21, 2017 at 19:26

1 Answer 1


Maybe somebody needs the code which creates connected app.

MetadataService.MetadataPort service = createService();
MetadataService.ConnectedApp connectedApp = new 

connectedApp.label = 'Test 005';
connectedApp.fullName = 'Test_005';
connectedApp.contactEmail = 'email@email.com';

MetadataService.ConnectedAppOauthConfig oauthConfig = new 

oauthConfig.consumerKey = 'yourConsumerKey';
oauthConfig.consumerSecret = 'yourConsumerSecret';
oauthConfig.scopes = new List<String>{'Basic', 'Api', 'Web', 'Full'};
oauthConfig.callbackUrl = 'https://www.google.com/';

connectedApp.oauthConfig = oauthConfig;

List<MetadataService.SaveResult> results = service.createMetadata(new 
MetadataService.Metadata[] { connectedApp });

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.