You need to sign in to do that
Don't have an account?
Marcio 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
I found the solution here:
http://boards.developerforce.com/t5/Apex-Code-Development/Simulate-a-profile-in-a-trigger-unit-test/m-p/113087#M12625
Tks
All Answers
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
I found the solution here:
http://boards.developerforce.com/t5/Apex-Code-Development/Simulate-a-profile-in-a-trigger-unit-test/m-p/113087#M12625
Tks