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
Brad007Brad007 

Upsert Operation

Hi I am doing a Apex callout and i need to get the Xml string data Map it and Upsert my Object. But i am confused here as with the Xml string data i have.  this is what i would get after my call out.

 

<APFilesData><APFiles1><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo1>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo1.jpg</Photo1><External_ID_Photo1>Test</External_ID_Photo1><InactivePhoto1_Dt>11/08/2011</InactivePhoto1_Dt></APFiles1><APFiles2><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo2>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo2.jpg</Photo2><External_ID_Photo2>null</External_ID_Photo2><InactivePhoto2_Dt></InactivePhoto2_Dt></APFiles2><APFiles3><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo3>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo3.jpg</Photo3><External_ID_Photo3>null</External_ID_Photo3><InactivePhoto3_Dt></InactivePhoto3_Dt></APFiles3><APFiles4><ApplicationId>a0B40000000vBJrEAM</ApplicationId><APID>0034000000SiXLtAAN</APID><Photo4>//Bait/Applications/AP Applications/AP0802720.Song/Photos/Photo4.jpg</Photo4><External_ID_Photo4>null</External_ID_Photo4><InactivePhoto4_Dt></InactivePhoto4_Dt></APFiles4><APFilesData>

 

So now i have a files object which has a External_Id__c field which should be mapped to the above external Ids. and then if i have a Inactive date populated in my xml i update or i insert new row into files with 4 values.

 

Dom.Document docx = new Dom.Document();  

 docx.load(ServiceResult);    

 Dom.Xmlnode xroot = docx.getRootElement();    

 Dom.Xmlnode [] xrec = xroot.getChildElements();  

 Files__c[]  upsertfiles = new Files__c[]{};    

 List<AP_Application__c> upsertApplications = new List<AP_Application__c>();        

 for(Dom.Xmlnode child : xrec)

 {

     Files__c file = new Files__c();

     for(Dom.Xmlnode node : child.getchildren())

    {// What should go here to have my upsert   }

    upsertfiles.add(file);

    system.debug('Result:' +upsertfiles);

     try {       

            upsert upsertfiles External_ID__c;     }    

        catch (DmlException e)

      {        System.debug(e.getMessage());    } }

 

 



For each photo file, create one row to be inserted into Files__c in SFDC.  Need the following columns:

Files__c

From

Contact__c

AP_Application__c.Au_Pair__c

AP_Application__c

AP_Application__c

Path__c

AP_Application__c.Photo1__c

External_ID__c

AP_Application__c. ExernalIdPhoto1

Inactive_Date__c

New column you create

UPSERT  Files

Use External Id to match Files__c. ExternalId

Files__c. AP_Application__c  = Application id

Files__c.Contact__c = Contact id

Files__c.Path__c = Path

Files__c.Inactive_Dt__c