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
Kashona DotsonKashona Dotson 

I need help writing Apex Test!

I have this Apex Class and my visualforce page and they work beautifully but I need to get 75% test coverage! My brain is mush, I don't even know where to start...
 
public class multiAddRIM {
    
    List <RIM_Item__c> RIMitemList;
      public Id rID = ApexPages.currentPage().getParameters().get('Id');
      public Id getID {get; set;}
    
    public PageReference reset() {
      RIMitemList = [select name, RIM__c, Transaction_Type__c, Check_Number__c, Transaction_Amount_Detail__c, 
                     Fee_Detail__c, Decision__c from RIM_Item__c where RIM__c =: rID ];
      return null; }
    
    public List <RIM_Item__c> getRIMitems() {
      if(RIMitemList == null) reset();
      return RIMitemList;}
    
    public void setAccounts(List <RIM_Item__c> items) {
      RIMitemList = items;}
    
    public PageReference save() {//upsert records on save
      upsert RIMitemList;
      ApexPages.Message myMsg = new ApexPages.message(ApexPages.Severity.Info, 'Records Saved Successfully'); //show confirmation message on save
      ApexPages.addMessage(myMsg);
      return null;}
    
    public PageReference add() {
      RIMitemList.add(New RIM_Item__c(RIM__c = rID)); //add records to RIM Item and associate with current RIM Record
      return null; }
}

 
Raj VakatiRaj Vakati
Hi , 
Please refer this link for more information  Here is the basic code 
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm​
 
@isTest
private class multiAddRIMTest{
private  static testemthod void  testcasePostitive(){

RIM__c  rtm = new RIM__c ();
rtm.Name ='Test' ; 
insert rtm ; 

RIM_Item__c item = new RIM_Item__c(); 
item.Name = 'Test' ; 
item.RIM__c = rtm.Id ;

insert item ;

PageReference pageRef = Page.<Your page>;
        Test.setCurrentPage(pageRef);
      
        multiAddRIM controller = new multiAddRIM();
        ApexPages.currentPage().getParameters().put('Id',  rtm.id);
		
controller.reset();
controller.getRIMitems();
controller.add();
controller.save();





}

}





 
Kashona DotsonKashona Dotson
The rtm.Name field is an autonumber type which is not writable. How do I assign a value to the field so that it doesn't fail creation?
Raj VakatiRaj Vakati
Change the code to this line 
​controller.setAccounts(new List<RIM_Item__c>{item  }) ;