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
Mahesh GorrepatiMahesh Gorrepati 

Integration:- salesforce to salesforce using connected app. ERROR:- {"error":"invalid_grant","error_description":"authentication failure"}


public class Getaccounts_from_B {


    public  static  string apiclientid;

    public  static  string apiclientsecrete;

    public  static  string username;

    public  static  string  password;


    public static void getAuthCreds()


        salesforcetosalesforce__c clientid = salesforcetosalesforce__c.getInstance('Client ID');

        salesforcetosalesforce__c clientsecreate = salesforcetosalesforce__c.getInstance('Client secrete');

        salesforcetosalesforce__c clientusername = salesforcetosalesforce__c.getInstance('Username');

        salesforcetosalesforce__c clientpassword = salesforcetosalesforce__c.getInstance('password');


        apiclientid = clientid.value__c;

        apiclientsecrete =clientsecreate.value__c;

        username  =  clientusername.value__c;

        PASSWORD  = clientpassword.value__c;


    public class deserializeResponse


        public String id;

        public String access_token;


    public static  String ReturnAccessToken ()


        // method used authoentication details in the system. 



        String reqbody = 'grant_type=password'+'&client_id='+apiclientid+'&client_secret='+apiclientsecrete+'&username='+username+'&password='+PASSWORD;

        Http h = new Http();

        HttpRequest req = new HttpRequest();




        HttpResponse res = h.send(req);

        system.debug('The access token for the ' + res.getBody());

        deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);

        system.debug('The access token for the ' + resp1.access_token);

        return resp1.access_token;



Tried:- I have gone through web, they mentioned to change 

  1.  change "IP Relaxation" setting to "Relax IP Restrictions"
  2.  Access of the connect app:- it is also changed to self authorization.

Note:- i tried the solutions above, but the code is showing the same error. Kindly suggest any  other method to resolve the issue.

Sai PraveenSai Praveen (Salesforce Developers) 
hi Mahesh,

Can you check the below article where step by steps were mentioned here using trigger on Account.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Mahesh GorrepatiMahesh Gorrepati
Thank you . my issue is resolved