0

I have installed a connected app with the help of a package. And now I want to update it's metadata like 'Canvas App URL' with the help of Metadata API.

First of all, I tried to read all information about the installed connected app via Metadata API. Below is the code to read connected app via Metadata API. All the fields that I am getting in debug are null.

    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[] {'MyConnectedApp'}).getRecords()[0];
System.debug(connectedApp);

Below is the debug I am getting.

USER_DEBUG [6]|DEBUG|ConnectedApp:[Metadata.fullName=null, apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), attributes=null, attributes_type_info=(attributes, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), canvasConfig=null, canvasConfig_type_info=(canvasConfig, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), contactEmail=null, contactEmail_type_info=(contactEmail, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), contactPhone=null, contactPhone_type_info=(contactPhone, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, attributes, canvasConfig, contactEmail, contactPhone, description, iconUrl, infoUrl, ipRanges, label, ...), fullName=null, fullName_type_info=(fullName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), iconUrl=null, iconUrl_type_info=(iconUrl, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), infoUrl=null, infoUrl_type_info=(infoUrl, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), ipRanges=null, ipRanges_type_info=(ipRanges, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), label=null, label_type_info=(label, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), logoUrl=null, logoUrl_type_info=(logoUrl, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), mobileAppConfig=null, mobileAppConfig_type_info=(mobileAppConfig, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), mobileStartUrl=null, mobileStartUrl_type_info=(mobileStartUrl, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), oauthConfig=null, oauthConfig_type_info=(oauthConfig, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), plugin=null, plugin_type_info=(plugin, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), samlConfig=null, samlConfig_type_info=(samlConfig, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), startUrl=null, startUrl_type_info=(startUrl, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=ConnectedApp, type_att_info=(xsi:type)]

My main purpose is to read the metadata of an installed connected app and update it's canvas app url. I went through all the references available online, but nothing seems helpful right now.

Can this be handled with Canvas Lifecycle Handler class?

0

I figured out why I was getting null values for metadata of connected app. This was because, I was trying to read metadata of connected app in org which had a namespace prefix set.

So, if you're trying to read metadata of connected app make sure you prepend the namespace prefix of the subscriber's org.

So, just one small change in code will be to add namespace prefix before the name of your connected app.

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[] {'namespaceprefix__MyConnectedApp'}).getRecords()[0];
System.debug(connectedApp);

This can be the case with any metadata (not just connected app) you're trying to read in the subscriber's org with a namespace prefix set.

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.