function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
manjirimanjiri 

How to check other organization information from apex class in my organization

       

Hi,

 

I want to login to other salesforce organization and check wheather particular vf page exist or not on that org.

If present i want to redirect to that page on that org. Else want to show error page on my org.

I want to write the code in my Apex class.

For login I have used REST call. Configured https://login.salesforce.com in remote site settings.

Following is my code for login.

 

        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint('https://login.salesforce.com/?un='+userName+'&pw='+password+'&startURL=/apex/ABCPage');
       
        Http http = new Http();
        PageReference p;       
   
        try {
            HTTPResponse res = http.send(req);   
            showError = true;

            if(res.getStatusCode()== 302)
            {
                p = new PageReference('https://login.salesforce.com/?un='+userName+'&pw='+password+'&startURL=/apex/ABCPage');           
                showError = false;
            }

        } catch(System.CalloutException e) {
            //Exception handling goes here....
             System.debug('In catch '+e);           
        }

I don't know is it a right way? Please let me know if any other alternative possible? i am able to login and show that page using this code.

 

Same way is it possible to call Metadata API? Is there any endpoint available?

Or is there any other way to check if particular vf page i.e 'ABCPage' exist or not on other org through Apex code in my org?

 

i can get list of page in my org using

List<ApexPage> lstPages = [Select id, name from ApexPage];

Is there any way to get this list for other org?

 

Thanks..

 

Anand@SAASAnand@SAAS

This is not the recommended way and salesforce does not expose Meta data through the HTTP URL. You will have to write something using the Meta data API in order to accomplish what you are trying to do.