+ 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
      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 
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>;
        multiAddRIM controller = new multiAddRIM();
        ApexPages.currentPage().getParameters().put('Id',  rtm.id);



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  }) ;