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
RaffusRaffus 

How do I parse a JSON map into an Apex Map in Object

I want to coverage for this method-
 
@future (callout=true)
    public static void fetchDetailsAndUpdateOmniCustomer(String emailid, String empid, String jwttoken) {  //
        Omni_App_Customer__c customer = [SELECT Id,Name, Customer_Last_Name__c, Customer_Email__c, Customer_Photo_Base64__c, Customer_Emp_ID__c, Customer_First_Name__c, Customer_Name__c, Party_Id__c FROM Omni_App_Customer__c WHERE Customer_Email__c= : emailid];
        System.debug('customers getOrCreateCustomer' + customer);

        String employeeDetails = getDataFromEmployee(empid, emailid, jwttoken);//String 
        Map<String, Object> employeeAllData = (Map<String, Object>)JSON.deserializeUntyped(employeeDetails);
        Map<String, Object> empCardDetails = (Map<String, Object>)employeeAllData.get('EmpCardDetailsOutputParameters');
        System.debug('customers empCardDetails' + empCardDetails);
        If(empCardDetails != null){
            Map<String, Object> p_refcur = (Map<String, Object>)empCardDetails.get('P_REFCUR');
            System.debug('customers p_refcur' + p_refcur);
            If(p_refcur != null){
                Map<String, Object> row = (Map<String, Object>)p_refcur.get('Row');
                System.debug('customers row' + row);
                List<Object> employee = (List<Object>)row.get('Column');
                for(object obj : employee){
                    String employeeData = JSON.serialize(obj);
                    if(employeeData.contains('FIRST_NAME')){
                    customer.Customer_First_Name__c = getFieldValue(employeeData);
                    customer.Name = customer.Customer_First_Name__c;
                    }else if(employeeData.contains('LAST_NAME')){
                        customer.Customer_Last_Name__c = getFieldValue(employeeData);
                        customer.Name = customer.Name +' '+customer.Customer_Last_Name__c;
                    }else if(employeeData.contains('EMPLOYEE_PHOTO')){
                    String empPhoto = getFieldValue(employeeData);
                     if(String.isNotBlank(empPhoto)){
                        String empPhotoFinal =  empPhoto.replaceAll('\n', '');
                        customer.Customer_Photo_Base64__c = 'data:image/jpeg;base64,'+empPhotoFinal;
                     }
                    }else if(employeeData.contains('DEPARTMENT')){
                    customer.Customer_Department__c = getFieldValue(employeeData);
                    } 
                }
            }
        }
        customer.recalculateFormulas();
        System.debug('before upsert FromFuture customer ' + customer);
        upsert customer;
    }

My written test class but not able to put data for map
@IsTest
    public static void fetchDetailsAndUpdaterandCustomerTest(){
        
        // String employeeDetails = '{"emailid":["emailid":"test@g.com"]}';
        // randAppController.saveCustomerInfo(jsoninput,'12133','09922982822');
        rand_App_Customer__c randCustomer = new rand_App_Customer__c();
        randCustomer.Customer_ID__c = '1234567';
        randCustomer.Customer_First_Name__c = 'Test rand';
        randCustomer.Customer_Last_Name__c = 'Customer';
        randCustomer.Party_Id__c = '8545254752';
        randCustomer.Customer_Mobile__c = '8545254752';
        randCustomer.Customer_Email__c = 'tannow@tan.ae';
        randCustomer.Customer_Emp_ID__c = '012081';
        randCustomer.Customer_Points__c = 150;
        randCustomer.Customer_Department__c = 'EMG - Leasing';
        Insert randCustomer;
        
        
        String jwttoken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0LXN1YmplY3QiLCJhdWQiOlsiYXVkaWVuY2UxIiwiYXVkaWVuY2UyIl0sImlzcyI6InVybjpcL1wvYXBpZ2VlLWVkZ2UtSldULXBvbGljeS10ZXN0IiwiYWZmaWxpYXRlIjoiZmFsc2UiLCJleHAiOjE2NjIxODUwMTUsInVzZXJpZCI6IkVtYWFybm93IiwiaWF0IjoxNjYyMTEzMDE1LCJqdGkiOiJjYWNkN2MxZC02NDY5LTQyMjUtYmU5ZC0yZDExNmFkMjk0MGUiLCJ1c2VybmFtZSI6IkVtYWFybm93QGVtYWFyLmFlIn0.BJRby7mdcJ_IAoEJJwruGJod6dd8IS3nuWOQIK0dFhU';
        String employeeId = '012081';
        String employeeEmail = 'tannow@tan.ae';
        
        String employeeDetails = '{"EmpCardDetailsOutputParameters": { "P_REFCUR": { "Row": { "Column": [{ "@name": "EMPLOYEE_NAME","@sqltype": "VARCHAR2","TEXT": "Shinu  Sony"},{"@name": "EMPLOYEE_NUMBER","@sqltype": "VARCHAR2","TEXT": "011380"},{"@name": "DESIGNATION", "@sqltype": "VARCHAR2","TEXT": "Product Owner"},{"@name": "DEPARTMENT","@sqltype": "VARCHAR2","TEXT": "Information Technology"},{"@name": "ENTITY","@sqltype": "VARCHAR2","TEXT": "tan Properties P.J.S.C."},{"@name": "EMAIL_ADDRESS","@sqltype": "VARCHAR2","TEXT": "SSony@tan.ae"},{"@name": "PHONE","@sqltype": "VARCHAR2","TEXT": "+971567646583"},{"@name": "COMPANY_CODE","@sqltype": "VARCHAR2","TEXT": "Non EHG"},{"@name": "FIRST_NAME","@sqltype": "VARCHAR2","TEXT": "Shinu"},{"@name": "LAST_NAME","@sqltype": "VARCHAR2","TEXT": "Sony"},{"@nil": "true","@name": "MIDDLE_NAMES","@sqltype": "VARCHAR2"},{"@name": "LOGO_NAME", "@sqltype": "VARCHAR2","TEXT": "tan Properties P.J.S.C."},{"@name": "EMPLOYEE_PHOTO", "@sqltype": "CLOB","TEXT": "test" } ]}}}}';
        Map<String, Object> employeeAllData = (Map<String, Object>) JSON.deserializeUntyped(employeeDetails);
        Map<String, Object> empCardDetails = (Map<String, Object>)employeeAllData.get('EmpCardDetailsOutputParameters');
        Map<String, Object> p_refcur = (Map<String, Object>)empCardDetails.get('P_REFCUR');
        Map<String, Object> row = (Map<String, Object>)p_refcur.get('Row');
        List<Object> employee = (List<Object>)row.get('Column');
        	
        
        Test.startTest();
        try
        {
            
            randAppController.fetchDetailsAndUpdaterandCustomer(employeeEmail, employeeId, jwttoken);
       
        }
        catch(exception e)
        {
        }     
        Test.stopTest();
        
    }



​​​​​​​