You need to sign in to do that
Don't have an account?
Ishwar Shinde
Read timed out error on calling apex rest api through Named Credentail
I am trying to access the apex rest service defined in Salesforce org B from Salesforce org B using named credentails.
I have performed following steps-
I am getting read timed out error/ Unexpected end of file from server if timed out is set to 120 seconds.
I have whitlisted all ip addresses in Network setting.
Could you please help what is wrong here?
Thanks in advance.
I have performed following steps-
- Create Connected App in Salesforce Org B
- Create Auth. Provider in Salesforce Org A, add consumer secret and key. Copy callback URL.
- Update Connected App in Salesforce Org B with Callback URL.
- Go to Org A --> Create Named Credential --> Select the Oauth --> Select the Auth Provider created earlier --> Set scope as refresh_token full
-> Start Authentication Flow on Save --> authorize using Org B - Use this Named Cred. in Apex code.
HttpRequest req = new HttpRequest(); req.setEndpoint('callout:Connect_to_My_Salesforce_Org/services/apexrest/account/'); req.setBody('{"accId":"'+accId+'"}'); req.setMethod('POST'); req.setTimeout(12000); req.setHeader('Content-Type', 'application/json'); Http h = new Http(); HttpResponse res; res = h.send(req); System.debug(' Response '+ res); System.debug(' Body '+ res.getBody());
I am getting read timed out error/ Unexpected end of file from server if timed out is set to 120 seconds.
I have whitlisted all ip addresses in Network setting.
Could you please help what is wrong here?
Thanks in advance.
All Answers
Here is the simple code in Org B -
My goal is to make callout from salesforce to salesforce using Named Credentail. Same functionality is working when I tried with explicit Oauth authetication in code.
Also, try by removing this line.
req.setHeader('Content-Type', 'application/json');
Regards,
Sridhar
I have added content type after getting an error related to content type.
I am currently using oauth2 Authentication in named credentail. What is the reason for selecting password authentication? [I tried that but getting the same error]
Named Credentail with Oauth 2
Named Credentail with Password Auth