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

 

I am struggling to cover test class for global static method in apex class.

 

apex class

 

global class locationExtension{

 

    

 

    public Decimal lat{ get; set;}

 

    public Decimal lon{ get; set;}

 

    public static string contactId {get;set;}

 

    public static Activity_Master__c contctRec {get;set;}

 

    public locationExtension(ApexPages.StandardController controller) {

 

        contctRec = [SELECT Id FROM Activity_Master__c  WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

 

        contactId  = contctRec.Id;

 

        system.debug('=========='+contctRec);

 

    }

 

    

 

    @RemoteAction

 

    global static void getAccount(Decimal lat,Decimal lon,Id contactId) {

 

           

 

            system.debug('inside remote action m ethod'+lat+'--lon--'+lon);

 

            system.debug('=========='+contctRec);

 

            Activity_Master__c updateCont = new Activity_Master__c (id = contactId);

 

            updateCont.Location__Latitude__s = lat;

 

            updateCont.Location__Longitude__s = lon;

 

            update updateCont;

 

            

 

            system.debug('---updateCont--'+updateCont);

 

        }

 

   

 

}

 

 

Test Class:

 

@isTest(seeAllData=true)

 

public class locationExtensionTest {

 

    static TestMethod void Position() {

 

        String contactid;

 

        Decimal lat;

 

        Decimal lon;

 

        

 

        Account acc = new Account();

 

        acc.Name = 'Test';

 

        acc.Next_Followup_Date_Time__c = Datetime.Now();

 

        acc.Phone = '+919876543210';

 

        insert acc;

 

        

 

        Contact con = new Contact();

 

        con.LastName = 'test07';

 

        con.FirstName = 'demo07';

 

        con.Email = 'test1contct@duptest.com';

 

        con.AccountId = acc.id;

 

        con.OtherStreet = 'Bangalore';

 

        con.OtherCity= 'Bangalore';

 

        con.OtherState = 'Karnataka';

 

        con.OtherCountry ='Ind';

 

        con.OtherPostalCode='123456';

 

        con.Description ='123456';

 

        con.Approved__c = true;

 

        con.OtherCountry = 'Ind';

 

        con.MailingPostalCode='123456';

 

        con.Verified__c = 'Yes';

 

        con.Blue_Metal__c = true;

 

        con.Location_Map__Latitude__s=12.915578;

 

        con.Location_Map__Longitude__s=80.229227;

 

        con.Location_Map_new__Latitude__s=12.915578;

 

        con.Location_Map_new__Longitude__s=80.229227;

 

        insert con;

 

        

 

        Activity_Master__c AM = new Activity_Master__c();

 

        AM.Location__Latitude__s = 1.0000;

 

        AM.Location__Longitude__s = 2.0000;

 

        contactid = AM.Id;

 

        Insert AM;

 

        

 

        System.currentPagereference().getParameters().put('Id',AM.id);

 

        ApexPages.StandardController sc =new ApexPages.StandardController(AM);

 

        locationExtension l = new locationExtension(sc);

 

        Test.startTest();

 

        l.lat =  1.000;

 

        l.lon = 2.000;

 

        Test.stopTest();

 

   

 

    }

 

}
3 réponses
  1. 7 juil. 2020, 11:20
    Hi Raja,

     

    Below line not get covered.

     

            contctRec = [SELECT Id FROM Activity_Master__c  WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

     

            contactId  = contctRec.Id;
0/9000