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
Dippan PatelDippan Patel 

API call to salesforce gives error 503 for a particular instance

string server = null;
String host = URL.getSalesforceBaseUrl().getHost();
if(host.split('\\.')[2] == 'visual'){
	server = host.split('\\.')[1];            
}
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://' + server + '-api.salesforce.com/services/data/v34.0/sobjects/' + objName + '/describe/layouts/' + recordTypeId);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Sforce-Call-Options', 'client=x');
Http http = new Http();
HTTPResponse res;
res = http.send(req);

This gives response: 

Request
|System.HttpRequest[Endpoint=https://na70-api.salesforce.com/services/data/v34.0/sobjects/Account/describe/layouts/01280000000HmSj, Method=GET]

Response
System.HttpResponse[Status=Service Unavailable, StatusCode=503] 

I also checked  
https://status.salesforce.com/instances/NAX/maintenances and looks all good. 

Can anybody help me figure out why is this occurring for a particular instance only? 
Best Answer chosen by Dippan Patel
Nayana KNayana K
Not sure what can be the reason. Looks like the rest api you are making is for the current org. Can you try this way:
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()+'/services/data/v34.0/sobjects/' + objName + '/describe/layouts/' + recordTypeId);