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
Santosh SSantosh S 

Request Help for the Apex Code test

public with sharing class extLogACase 
{     

  private final Case webCase;    
  private final Case twebCase;    
  public extLogACase(ApexPages.StandardController   stdController) 
    {       
         webCase= (Case)stdController.getRecord();        
         webCase.put('Origin', 'Web');        
        webCase.put('Case_Account__c', ApexPages.currentPage().getParameters().get('CurrentAccount'));                
        webCase.put('Case_Reported_By__c', ApexPages.currentPage().getParameters().get('LoggedInUser'));       

    }     

 public PageReference logCase() 
    {        
                 try {       
                          insert(webCase);       
                      }       
           
                catch(System.DMLException e)
                    {            ApexPages.addMessages(e);            
                                 return null;       
                    }       
      PageReference p = Page.ThankYou;        
      p.setRedirect(true);       
      return p;     
   }           
 
  public PageReference resetCase() 
    {               webCase.put('Subject', 'S');        
                    webCase.put('Description', 'D');        
                    PageReference p1 = Page.My_Cases;       
                   p1.setRedirect(true);        
                   return p1;      
    }     



 }

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

try this :

 

static testMethod void main() {

Account a = new Account(Name = 'test');

insert a;

 

Case c = new Case();
system.currentPageReference().getParameters().put('CurrentAccount', a.Id);

system.currentPageReference().getParameters().put('LoggedInUser', UserInfo.getUserId());
ApexPages.Standardcontroller obj = new Apexpages.Standardcontroller(c);
extLogCase extLogCaseObj = new extLogCase (obj);
extLogCaseObj.logCase();
extLogCaseObj.resetCase();
}

 

for more information follow:

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

All Answers

Laxman RaoLaxman Rao

try this :

 

static testMethod void main() {

Account a = new Account(Name = 'test');

insert a;

 

Case c = new Case();
system.currentPageReference().getParameters().put('CurrentAccount', a.Id);

system.currentPageReference().getParameters().put('LoggedInUser', UserInfo.getUserId());
ApexPages.Standardcontroller obj = new Apexpages.Standardcontroller(c);
extLogCase extLogCaseObj = new extLogCase (obj);
extLogCaseObj.logCase();
extLogCaseObj.resetCase();
}

 

for more information follow:

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

This was selected as the best answer
Santosh SSantosh S

Thanks