• ashish saxena 25
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi All i am trting to create a user in salesforce using REST api through uipath.
i am getting invalid session id error.  
But when i am trying to create a user using REST api through postman ,i am able to create the user .
pleas help me for the same
Hi All,

I am trying to connect one sf org to anaother. I am using the below class to initiate the call from command button. I copied session id of target org and hard coded here in the class which then worked. But for next time it expires and i get invalid session id.

Can anyone help me out how i can dynamically have the session id of source org, so that i need not to hard code it.

public class Apex_Rest_DemoController {
    
    public String response{get;set;}
    public String accName{get;set;}
    public String accPhone{get;set;}
    public String accWebsite{get;set;}
    
    public PageReference CreateAccount() {
        //find access token using Auth 2.0 
       String Access_Token = '00D28000000Heme!AQ8AQAFOnSjXlGvbNT9JXj5vcC2XjQyFtz8ls_x0IMmoDuX91WDLvb9j5qficiTwQpCGjTYIRCUOmvwQOlWvP2.0HPA3x9M.';
       
        Httprequest req=new httprequest();
        String domainName='ap2.salesforce.com';

        String endPointURL='https://'+domainName+'/services/data/v34.0/sobjects/Account';
        req.setendpoint(endPointURL);
        req.setHeader('Content-Type', 'application/xml; charset=utf-8');
        req.setBody('<?xml version="1.0" encoding="UTF-8" ?><request><name>'+accName+'</name><phone>'+accPhone+'</phone><website >'+accWebsite+'</website > </request>');
        req.setmethod('POST');
        req.setHeader('Authorization','Authorization: Bearer '+Access_Token);
        //req.setHeader('Authorization','Bearer '+Access_Token);
        //req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
        Http http = new Http();
        HTTPResponse res = http.send(req);
        response=res.getbody();
        System.debug('****************res.getStatusCode();'+res.getStatusCode());
        System.debug('****************res.getbody();'+res.getbody());
        return null;
    }
}

Regards