+ Start a Discussion
Marcio Zima.ax1538Marcio Zima.ax1538 

Test Class - UserInfo.getProfileId() and Profile

I'm trying to cover the following trigger:

public PageReference redirect() {
  Profile p = [select name from Profile where id = 
			   :UserInfo.getProfileId()];
  if ('Manager'.equals(p.name) 
	  || 'Client'.equals(p.name)) 
	  {
	   PageReference customPage =  Page.info;
	   customPage.setRedirect(true);
	   customPage.getParameters().put('id', recordId);
	   return customPage;
	  } else {
		  return null; //otherwise stay on the same page  
	
	  }
   }

 

At the moment  my following test class has been covering 63% of the code:

static testMethod void testoverrideCon() {

Profile pr = [select name from Profile where id = 
			   '00e34200001nqX5'];
Apexpages.StandardController stdController = new Apexpages.StandardController(new Profile()); 
    overrideCon testPRTC = new overrideCon(stdController);

    testPRTC.redirect();
    

  }

 I'm having problem to cover these specific lines:

if ('Manager'.equals(p.name) 
	  || 'Client'.equals(p.name)) 
	  {
	   PageReference customPage =  Page.info;
	   customPage.setRedirect(true);
	   customPage.getParameters().put('id', recordId);
	   return customPage;

 

Anyone have any suggestion to solution?

 

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

VaasuVaasu

Hey ZIMA,

 

Are you sure you are getting correct profile name, in this case Manager or Client and change the code to "EqualsIgnoreCase" instead of "Equals" this will ignore the case of profile name.

 

Thanks