Getting production organization ID from sandbox using API

Is there a queryable ressource through the API from a Salesforce sandbox instance that can return the related production environment organization ID?

Answer

Got production org id by parsing Deployment Settings page right from apex code:

// get content of 'Deployment Connections' page from setup
String pageContent = new PageReference('/changemgmt/deploymentSettings.apexp').getContent().toString();

// regex to parse producion org id from html table markup
Pattern productionOrgIdRegEx = Pattern.compile('(?i)/changemgmt/deployConnectionDetailPage.apexp?id=(\\w+)');

Matcher matcher = productionOrgIdRegEx.matcher(pageContent);

String productionOrgId = 
    matcher.find() 
    ?
        matcher.group(1).trim()
        :
        null
;

System.assertEquals(
    null,
    productionOrgId
);

enter image description here

Attribution
Source : Link , Question Author : jpmonette , Answer Author : wesaw

Leave a Comment