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

Adding records from one org to another



All I want to do is login to org1 and press a button that adds an Account to org2 (all I need in response is the Id of the record that was created). I am basically lost with all the different information on the web. I'm currently using user+pass for authentication in my HttpRequest POST call and it's giving me back an invalid session id error. Here are some of the resources that I have read through:


There's all these talks about tokens, OAuth, session id, remote access services, etc. which have completely lost me.


Here's my method:

    public String sendToOrg(String j, String url, String user, String pass)
        HttpRequest req = new HttpRequest();
        Blob headerValue = Blob.valueOf(user + ':' + pass);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        Http http = new Http();
        HTTPResponse resp = http.send(req);
        system.debug('**** Response: ' + resp.getBody() );
        if (resp != null && resp.getBody() != null) return resp.getBody();   
        else return null;

 with url being:


I'd really appreciate a straight-forward, Apex oriented guidance!


Hi ,
You can achieve it using METADATA WSDL.For login into org2 from org 1 use the partner WSDL of org2,generate the APEX class from it and call the login() method of the generated class.With this ,you can obtain the session id.
Now parse and generate the apex class from metadata wsdl.Instantiate this class,add the session id to the session header property of it.Instantiate the createfield class of the metadata class and create the field with the required fields value.