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
Nitin sharma 425Nitin sharma 425 

Callouts and Integration

Hi All, Below given code is part of the code which I have used to create and update contact records in another salesforce Org.It between salesforce to salesforce and I am able to create and update records in another org.However,After I made a callout I debug the response and tried to pull out External Id field from it...I wanted to update External ID field in Org1 with the id of the contact created in Org2 So when I used system.debug to see what's in the response. I could see External Id field with a value in it but after I looped through the returned contacts I only saw null in the External Id....Not sure what's going on.....How do I pull out external Id field from the response and update the contact field with the Id of the contact from org 2 as as External Id field in org 1?....I know I can use map to map external id with the Id of contact in map from Org1 and then update the contact field with the Id of the contact from org2...If somebody can help me in telling why I am not able to see External id field in reponse
System.debug('The response is********************'+response.getbody());

The above line has external Id value

The below line give me null

system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);

    if(accessTokenWrapperObj != null)
        String endpoint = '';
        String requestBody = JSON.serialize(ContactList);
        HTTP http = new HTTP();
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization', 'Bearer '+accessTokenWrapperObj);
        HttpResponse response = http.send(request);
        System.debug('The response is********************'+response.getbody());
        list<contact>updatecontactlist=new list<contact>();
        list<contact> con=(List<contact>) System.JSON.deserialize(response.getbody(),List<contact>.class);

        for(contact conReturned:con)

         system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
          system.debug('The contact variable Conrec has the following values';
            contact c=new contact();
        //update updatecontactlist;
        //System.debug('The updated record is'+updatecontactlist);
        //System.debug('Status code:'+response.getStatusCode()+'==>'+response.getBody());


Ajay Patel 54Ajay Patel 54

hi  Nitin 

hope these will help you 

                if( httpRes.getStatusCode()==200){
                    Map<String,object> data1 = (Map<String, object>) JSON.deserializeUntyped(httpRes.getBody());
                        contact  c = new contact ();
                        c.Id = conReturned.Id;
                        c.Contact_Id_As_ExternalId__c =string.valueof(data1.get('id'));
                system.debug('---Update Id--'+toBeUpdated);
                if(!toBeUpdated.isEmpty() && toBeUpdated.size()>0){
                    update toBeUpdated;