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
eBiz03eBiz03 

help with writing test class

I would be so grateful if anyone could help with a test class for my controller. New to apex and trying to get this in my production environment. Thanks in advance for any help.

 

public with sharing class massupdatefield{

public List<Contact> contacts{get; set;}
public list<selectoption> options{Get; set;}
public string selected{get; set;}
String saveUrl = ApexPages.currentPage().getParameters().get('retURL');

public massupdatefield(apexpages.standardsetcontroller ssc){
    contacts = (list<contact>)ssc.getSelected();
    Schema.DescribeFieldResult FR = Contact.Rep_Call_List__c.getDescribe();
    List<Schema.PicklistEntry> PL = FR.getPicklistValues();
    options = new list<selectoption>();
    for(schema.PickListEntry p:PL){
       options.add(new selectoption(p.getLabel(), p.getvalue()));
    }
 
}

public pagereference updatecontacts(){

for(Contact c:contacts){
     c.Rep_Call_List__c = selected;
    }
   update contacts;

return new pagereference(saveurl);
}
}

kiranmutturukiranmutturu

in the test class i used the email field you have to use the your required field.....

 

@isTest
private class testmw{

    static testmethod void hkjs(){
    
        contact objc = new contact();
        objc.lastname = 'test';
        insert objc;
        list<contact> lstcon = new list<contact>();
        lstcon.add(objc);
        ApexPages.currentPage().getParameters().put('retURL', '');
        ApexPages.StandardSetController ApptController = new ApexPages.StandardSetController(lstcon);
        massupdatefield obj = new massupdatefield(ApptController);
        obj.updatecontacts();
    }
}

 

Regards,

 

kiran