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
Sree SalesforceSree Salesforce 

System.JSONException: Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value at [line:1, column:3254]

When i Ran test Class I Am getting the issue.
Class.System.JSON.deserializeUntyped: line 11, column 1
Class.GroupAndEntitiesExtension.getEntityData: line 182, column 1
Class.GroupAndEntitiesExtension_Test.GroupAndEntitiesExtension_Test: line 77, column 1

Apex Class:- 

global class GroupAndEntitiesExtension {
    
    //variables
    public String eListData{get;set;}
    public String eListDataEdit{get;set;}
    public string groupId{get;set;}
    public string inputvalue{get;set;}
    public list<WrpperGroups> groupsearchlist{get;set;}
    public boolean showtable{get;set;}
    public Integer rowIndex {get;set;}
    public list<odm__C> deleteOdmrecords;
    public list<capital__C> deleteCapitalrecords;
    public list<ownership__c> deleteOwnershiprecords;
    public odm__c od;
    public capital__C captl;
    public Ownership__c ownrs;
    Public Service_Request__c serviceRequest{get;set;}
    public List<ODM__c> ODM {get;set;} 
    public List<Capital__c> capital {get;set;}
    public List<Ownership__c> Ownership {get;set;}
    public string groupsearchname{get;set;}
    public Boolean isGuestUser{get;set;}
    public String operation {get;set;}
    public String title {get;set;}
    public string conid{get;set;}
    public Id caseId;    
    public Boolean showFeed{get;set;}// to simulate standard feed functionality
    public transient Cookie feedCookie{get;set;}// to simulate standard feed functionality
    public Boolean feedView{get;set;} //Need to be removched
    Case caseRecord;
    public String serviceReqAction {get;set;}
    public List<SelectOption> servReqActionList{get;set;}
    public string groupaccountId{get;set;}
    List<entity__c> entitylist;
    public List<String> alphabets{get;set;}
    List<WrpperGroups> Tempwrapperlist= new List<WrpperGroups>();
    public List<Service_Request_Entity_Junction__c > entityViewtable{get;set;}
    public Boolean showGroupAndEntitiyTable{get;set;}
    public Boolean showGridError{get;set;}
    public String jsonEntityResponse{get;set;}
    public List<WrpperEntities> jsonEntitiesSelectAll;
    
    public GroupAndEntitiesExtension(ApexPages.StandardController stdcontroller){ 
        entitylist = new List<entity__c>();
        eListData =''; eListDataEdit = '';
        entityViewtable=new List<Service_Request_Entity_Junction__c>(); 
        od = new ODM__c();
        captl = new capital__C();
        ownrs = new Ownership__c();
        ODM = new List<ODM__c>();
        Capital = new List<Capital__c>();
        Ownership = new List<Ownership__c>();
        deleteOdmrecords=new List<odm__C>();
        deleteCapitalrecords=new List<capital__c>();
        deleteOwnershiprecords=new List<ownership__c>();
        groupsearchlist= new List<WrpperGroups>();
        alphabets=new List<string>{'All','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};  
            isGuestUser = (UserInfo.getName() == Label.Guest_User);
        showGridError = false;
        system.debug('=========================operation ======='+ApexPages.currentPage().getParameters().get('operation'));
        // logic for new service request
        if(ApexPages.currentPage().getParameters().get('id') == null){   
            operation = 'New';
            serviceRequest = new Service_Request__c();
            BillingFormHelper.readPageParameters(ApexPages.currentPage().getParameters(),serviceRequest);
            serviceRequest.Recordtypeid = Utils.fetchRecordTypeId('Service_Request__c','Entity Update');            
            if(isGuestUser){
                title = 'New Service Request';
            }
            else{
                caseId = ApexPages.currentPage().getParameters().get('caseId');
                caseRecord = [Select Id,Status,caseNumber from Case where Id =: caseId];
                title = 'New Service Request for Case# '+caseRecord.CaseNumber;
            }
            congrouplist();  
            showtable=true;
            showGroupAndEntitiyTable = false;
        }
        // logic for existing service request
        if(ApexPages.currentPage().getParameters().get('id') != null){   
            operation = 'View';
            showtable = false;
            serviceRequest = (Service_Request__c)stdController.getRecord();
            // to simulate standard feed functionality
            conid =serviceRequest.Contact__c;
            system.debug('==========--conid--==================================='+conid);
            feedCookie = ApexPages.currentPage().getCookies().get('ShowFeedView');
            if (feedCookie == null)
                feedCookie = new Cookie('ShowFeedView','False',null,-1,false);
            else 
                showFeed = (feedCookie.getValue() != 'False' );       
            entitytableView();
            showGroupAndEntitiyTable = false;
            fetchRelatedListData(serviceRequest.Id);
        }        
        if(ApexPages.currentPage().getParameters().get('operation') == 'Edit'){
            showGroupAndEntitiyTable = true;
            showtable = false;
            congrouplist(); 
            showEditScreen();        
        }
    }
    
    public List<Service_Request_Entity_Junction__c > entitytableView(){
        entityViewtable= [select Entity__r.name,Entity__r.Entity_ID__c,Entity__r.Entity_Party_ID__c from Service_Request_Entity_Junction__c where ServiceRequest__c=:serviceRequest.id];
        system.debug('--junlist--'+entityViewtable);
        return entityViewtable;    
    } 
    
    public void handleViewScreen(){
        System.debug('In handleViewScreen===='+ApexPages.currentPage().getParameters().get('id'));
        if(ApexPages.currentPage().getParameters().get('id') != null){  
            System.debug('serviceRequest.Id==='+serviceRequest.Id);
            //Code to Update the checkboxes if records are added from Related List.
            List<ODM__c> odmListAdded = new List<ODM__c>();
            odmListAdded = [select Id from ODM__c where Service_Request__c =: serviceRequest.Id];
            System.debug('odmListAdded===='+odmListAdded);
            if(odmListAdded.size()>0){
                serviceRequest.ODM__c = true;
            }else{
                serviceRequest.ODM__c = false;
            }
            List<Capital__c> capitalListAdded = new List<Capital__c>();
            capitalListAdded = [select Id from Capital__c where Service_Request__c =: serviceRequest.Id];
            if(capitalListAdded.size()>0){
                serviceRequest.Capital__c = true;
            }else{
                serviceRequest.Capital__c = false;
            }
            List<Ownership__c> ownerListAdded = new List<Ownership__c>();
            ownerListAdded = [select Id from Ownership__c where Service_Request__c =: serviceRequest.Id];
            if(ownerListAdded.size()>0){
                serviceRequest.Ownership__c = true;
            }else{
                serviceRequest.Ownership__c = false;
            }
            System.debug('serviceRequest===='+serviceRequest);
            update serviceRequest;
        }
    }
    
    @RemoteAction
    global static string getEntityData(String eSearchId){
        //To Do:
        // Create List of Wrapper
        // Get Results 
        // Iterate Through getting Next tag
        // Parse into List of Wrapper()
        // Run call for next result set
        // Add to List of Wrapper
        List<WrpperEntities> groupentitieslist=new list<WrpperEntities>();
        String bodyresp = '';
        system.debug('--groupaccountId--'+eSearchId);
        groupentitieslist.clear();  
        if(eSearchId=='' || eSearchId==Null){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please select group'));  
        }
        if(eSearchId!='' && eSearchId!=Null){
            List<WrpperEntities> eList = new List<WrpperEntities>();
            Boolean firstRun = true;
            Boolean hasNext = true;
            String nextUrl = '';
            Long startingTime = DateTime.now().getTime(); //track how long this takes
            while(hasNext){
                Long nowTime = DateTime.now().getTime();
                if(nowTime - startingTime > 110000){
                    WrpperEntities we = new WrpperEntities('00','The request for this groups list of entities took an extended amount of time. Please retry getting the entities. If this request continues to fail please contact Support.','','','');
                    groupentitieslist.add(we);
                    break;
                }
                if(firstRun){
                    bodyresp = APICalloutUtils.getEntityInfo(eSearchId);
                    system.debug('--==bodyresp'+bodyresp);
                    firstRun = false;
                }
                else{
                    bodyresp = APICalloutUtils.getNextEntityInfo(nextURL, eSearchId);
                    system.debug('--bodyresp'+bodyresp);
                }    
                
                Map<String,Object> jsonStub = new Map<String,Object>();
                jsonStub = (Map<String,Object>)JSON.deserializeUntyped(bodyresp);
                List<Object> entityJSONList = new List<Object>();
                entityJSONList = (List<Object>)jsonStub.get('entities');
                List<Object> linkObjectList = new List<Object>();
                linkObjectList = (List<Object>)jsonStub.get('links');
                
                Boolean nextURLFound = false;
                if(linkObjectList != null){
                    for(Object o : linkObjectList){
                        Map<String,Object> linkObjectMap = (Map<String,Object>)o;
                        List<Object> urlNameList = (List<Object>)linkObjectMap.get('rel');
                        String urlName = (String)urlNameList[0];
                        if(urlName == 'next'){
                            nextUrl = (String)linkObjectMap.get('href');
                            nextURLFound = true;
                            system.debug('NEXT URL Link FOR API CALL OUT TO ENTITIES: ==>>' + nextUrl);
                        }
                    }
                }
                if(nextURLFound == false)
                    nextUrl = '';
                
                if(Test.isRunningTest())
                    hasNext = false;
                
                if(nextUrl == ''){
                    hasNext = false;
                }
                system.debug('--body--'+bodyresp);
                System.debug('entityJSONList===='+entityJSONList);
                if(entityJSONList != null){
                    for(Object o : entityJSONList){
                        Map<String,Object> entityMap = (Map<String,Object>)o;
                        for(String s : entityMap.keySet()){
                            if(s == 'properties'){
                                Map<String,Object> propertiesMap = (Map<String,Object>)entityMap.get(s);
                                WrpperEntities we = new WrpperEntities(String.valueOf((Integer)propertiesMap.get('id')),(String)propertiesMap.get('entityName'),(String)propertiesMap.get('cscIndicator'), (String)propertiesMap.get('entityLegacyId'),(String)propertiesMap.get('cscStatus'));
                                groupentitieslist.add(we);
                            }
                        }
                    }
                }
                
            }
        }
        String jsonResult = json.serialize(groupentitieslist);
        system.debug('--------Complete Entity JSON Respose--------'+jsonResult);
        return jsonResult;
    }
    
    
PRIYANKA K2PRIYANKA K2
@Sree Salesforce ,
Did you get solution for this issue?? I am facing same issue while creating test class.