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
Vinothini murugesh 10Vinothini murugesh 10 

System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1)

Getting test class error:

handler  class:
public class IRIS_Contact_Campaign_Handler {
    
    public static boolean recursiveFlagCheck = false;
    
    // Defining the End Points of Marketing Cloud URL
    Static String MARKETING_CLOUD_AUTH_URL = 'https://auth.exacttargetapis.com/v1/requestToken';
    Static String ACCESS_TOKEN = 'accessToken';
    Static String MARKETING_CLOUD_ENDPOINT = 'https://webservice.s6.exacttarget.com/Service.asmx';
    
    // API Name of the Data Extension
    String DEAPIName = 'IRIS_Campaign_Email_Results_XREF';
    
    
    public IRIS_Contact_Campaign_Handler(){
        
        ACCESS_TOKEN = getMarketingCloudOAuthToken('abc', 'abc');
        performMCAction(ACCESS_TOKEN, DEAPIName);        
    }
    
    
     
    public static String makeSimpleJSONPostCall(String endPoint, String soapBody){
        
        Http h = new Http();
        HttpRequest  r = new HttpRequest();
        r.setTimeout(60000);
        r.setEndpoint(endPoint);  
        r.setMethod('POST');
        r.setHeader('Content-type','application/json');    
        r.setBody(soapBody);    
        HttpResponse res = h.send(r);
        System.Debug('makeSimpleJSONPostCall response: ' + res.getBody());
        //performMCAction(res.getBody().accessToken,DEAPIName);
        system.debug('Json values' + res.getBody());
        return res.getBody();
    }
    
    
    public static String makeHTTPXMLPost(String endPoint, String soapBody, String SOAPAction){
        Http h = new Http();
        HttpRequest r = new HttpRequest();
        r.setTimeout(60000);
        r.setEndpoint(endPoint);  
        r.setMethod('POST');
        r.setHeader('SOAPAction',SOAPAction); 
        r.setHeader('Accept','text/xml');  
        r.setHeader('Content-type','text/xml');    
        r.setHeader('charset','UTF-8'); 
        r.setBody(soapBody);    
        HttpResponse s = h.send(r);
        system.debug('Testing ' +s.getBody());
        
        DOM.Document doc = new DOM.Document();
        String toParse = s.getBody();
        doc.load(toParse);
        
        DOM.XMLNode root = doc.getRootElement();
        String nms = root.getNameSpace();
        List<IRIS_Contact_Campaign__c> concompans = New List<IRIS_Contact_Campaign__c>();
        system.debug('namespace--'+nms);
        DOM.XMLNode body = root.getChildElement('Body', nms);
        System.Debug('body: ' + body);
        List<DOM.XMLNode> bodyChildrenList = body.getChildElements();
        for (DOM.XMLNode passThroughReqResponse : bodyChildrenList) {
            //System.Debug('passThroughReqResponse: ' + passThroughReqResponse.getName());
            List<DOM.XMLNode> passThroughReqResultList = passThroughReqResponse.getChildElements();
            for (DOM.XMLNode passThroughReqResult : passThroughReqResultList){
                // System.Debug('passThroughReqResult: ' + passThroughReqResult.getName());            
                List<DOM.XMLNode> pickResponseList = passThroughReqResult.getChildElements();
                for (DOM.XMLNode pickResponse : pickResponseList) {
                    //System.Debug('pickResponse: ' + pickResponse.getName());
                    List<DOM.XMLNode> filesList = pickResponse.getChildElements();  
                    system.debug('Length ' + filesList.size());
                    if(filesList.size() != 0) {
                        IRIS_Contact_Campaign__c concmp = new IRIS_Contact_Campaign__c();
                        List<DOM.XMLNode> f1 = filesList[0].getChildElements();
                        List<DOM.XMLNode> f2 = filesList[1].getChildElements();
                        List<DOM.XMLNode> f3 = filesList[2].getChildElements();
                        List<DOM.XMLNode> f4 = filesList[3].getChildElements();
                        concmp.Campaign_ID__c = f1[1].getText();
                        concmp.Contact_ID__c = f2[1].getText();
                        concmp.Email_Subject__c = f3[1].getText();
                        concmp.Job_ID__c = f4[1].getText();
                        concompans.add(concmp);
                    }
                }
            }
        }
        if (concompans.size() != 0){
            system.debug('Marketing Values ' + concompans);
            if(!recursiveFlagCheck){
                insert concompans;
                
                recursiveFlagCheck = true;
            }
            
        }
        
        return s.getBody();
    }
    
    public static String getMarketingCloudOAuthToken(String clientId, String clientSecret){
        
        Marketing_Cloud_Credentials__c mcCredentials = Marketing_Cloud_Credentials__c.getValues('Marketing Cloud Credentials');
        String cId = mcCredentials.Client_Id__c;
        String cSecret = mcCredentials.Client_Secret__c;
        
        String responseBody = makeSimpleJSONPostCall(
            MARKETING_CLOUD_AUTH_URL,
            JSON.serialize( new Map<String, String>{
                'clientId' => cId,
                    'clientSecret' => cSecret
                    } )
        );
        string returnS = ((Map<String, String>) JSON.deserialize(responseBody, Map<String, String>.class)).get( ACCESS_TOKEN ); 
        System.debug('getMarketingCloudOAuthToken return value = ' + returnS);
        return returnS;
    }
    
    
    public static String performMCAction(String accessToken, String DEAPIName){
        String soapEnvelopeTemplate =  '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
            '       <Header>'+
            '          <fueloauth>{0}</fueloauth>'+
            '       </Header>'+
            '       <Body>'+
            '<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">'+
            '<RetrieveRequest>'+
            '<ClientIDs>'+
            '<ID>6422194</ID>'+
            '</ClientIDs>'+
            '<ObjectType>DataExtensionObject[IRIS_Campaign_Email_Results_XREF]</ObjectType>'+
            '<Properties>IRIS_Campaign_ID</Properties>'+
            '<Properties>Contact_ID</Properties>'+
            '<Properties>Email_Subject</Properties>'+
            '<Properties>ID</Properties>'+                         
            '</RetrieveRequest>'+
            '</RetrieveRequestMsg>'+
            '</Body>'+
            '    </Envelope>';
        System.debug('testting' + accessToken);
        String body = String.format(soapEnvelopeTemplate, new String[]{accessToken, DEAPIName});
        
        return makeHTTPXMLPost( MARKETING_CLOUD_ENDPOINT , body, 'Retrieve' );
    }
}



Test class:
@isTest
public class Iris_contact_campaign_handler_test {
    Static testmethod void test1(){
       // IRIS_Contact_Campaign_Handler c=new IRIS_Contact_Campaign_Handler();
        Marketing_Cloud_Credentials__c c=new Marketing_Cloud_Credentials__c();
        c.Client_Id__c='sdqpej9i0k3pj9j9tl4jpwfq';
        c.Client_Secret__c='nJYBnltT3N94f96cNtfcOhO3';
        c.name='Marketing Cloud Credentials';
        insert c;
        test.startTest();
        Test.setMock(HttpCalloutMock.class, new YourWebServiceMock());
        
        
         IRIS_Contact_Campaign_Handler c1=new IRIS_Contact_Campaign_Handler();
       
       

        test.stopTest();
    }   
    
}

Mock impl:
@isTest
global  class YourWebServiceMock implements HttpCalloutMock {
 global HTTPResponse respond(HTTPRequest req) {
 HttpResponse res = new HttpResponse();
 res.setHeader('Content-Type', 'application/Json');
    
 res.setBody('{"foo":"bar"}');
  res.setStatusCode(200);
     return res;

 }
}


Please help on this