Skip to main content
Mohankumar B a posé une question dans #Data Management
Hi all,

 

I am facing issue with test class. can anyone help me that?

 

apex class:

 

public with sharing class GeolocationController {

 

    public GeolocationController(ApexPages.StandardController controller){

 

        

 

    }

 

    @AuraEnabled

 

    public static void setLocation(String objectApiName, Map<String, Object> location, String recordId){

 

        sObject sObj = Schema.getGlobalDescribe().get(objectApiName).newSObject();

 

        sObj.put('Id', recordId);

 

        for(String field : location.keySet()){

 

            sObj.put(field, location.get(field));

 

        }

 

        update sObj;

 

    }

 

}

 

Testclass:

 

@isTest

 

public class GeolocationControllerTest {

 

     static Driver_Master__c Dms;

 

    static TestMethod void setLocation() 

 

    {

 

       

 

        Driver_Master__c DM = new Driver_Master__c();

 

        DM.City__c = 'test';

 

        DM.Name = 'test';

 

        DM.Pincode__c = '600012';

 

        DM.State__c = 'Test';

 

        DM.Street__c = 'Test';

 

        insert DM;

 

        

 

        System.currentPagereference().getParameters().put('id',DM.id);

 

        ApexPages.StandardController Controller = new ApexPages.StandardController(DM);

 

        GeolocationController Gc = new GeolocationController(Controller);

 

        GeolocationController.setLocation(Dms,10.00, DM.Id); ---> How to call the object api name

 

        

 

    }

 

}
21 réponses
  1. 30 juil. 2020, 09:25
    Hi Moustafa,

     

    Thanks for reply.

     

    Now i am getting below error:

     

    Error:System.SObjectException: Invalid field 10 for Driver_Master__c
0/9000