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
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

David HarborDavid Harbor
Handicap access specialists make this conceivable by running reviews of web assets and giving proposals on improving them. Web availability experts test your application or site (more info here https://mobilunity.com/blog/web-accessibility-consulting/). They likewise orchestrate preparing to assist your group with bringing issues to light of advanced incorporation.