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
Stephanie AkinStephanie Akin 

Help with a test class

Hi I have an apex class:
public with sharing class ProfileTabUserController {
// Purpose: Custom Chatter profile page
private ApexPages.StandardController c;
// Getter methods you can call from your Visualforce page, e.g. {!viewingMyProfile }
public User subjectUser { get; set; }
public boolean viewingMyProfile { get; set; } // Whether or not I’m viewing my profile
public String viewerID { get; set; } // UID string for the viewing user
public String subjectID { get; set; } // UID string for the subject user (being viewed)
// Constructor method for the controller
public ProfileTabUserController(ApexPages.StandardController stdController) {
c = stdController;
subjectID = getTargetSFDCUID();
// If we're operating inside a tab running inside of a profile...
if (subjectID != null) {
// Inject the sfdc.userId URL parameter value into the id param
// so the std User controller loads the right User record
ApexPages.currentPage().getParameters().put('id', subjectID);
}
// Load the User record for the user whose profile we’re viewing
this.subjectUser = (User)stdController.getRecord();
Id viewer = Id.valueOf(UserInfo.getUserId());
Id subject = Id.valueOf(subjectID);
viewingMyProfile = (viewer == subject);
viewerID = UserInfo.getUserId();
}
// Fetches URL parameter passed into a profile tab indicating which user is being viewed
private String getTargetSFDCUID() {
return
ApexPages.currentPage().getParameters().get('sfdc.userId');
}
// Overrides StandardController save method to force reload of current page afterwards
public PageReference save() {
c.save();
return ApexPages.currentPage();
}
// Overrides StandardController cancel method to force page reload
public PageReference cancel() {
c.cancel();
return ApexPages.currentPage();
}
}



But I need help with a test class. I have this but I keep getting error and it won't let me save. Can anyone help me fix the test class or help me to create a new one? Thanks in advance, here is the test class. 

@isTest
private class ProfileTabControllerTests {

private static testMethod void testProfileTabController() {

User u = [select Id from User where Id = :UserInfo.getUserId() ];

PageReference pageRef = Page.Chatter_Custom;
Test.setCurrentPage(pageRef);
ApexPages.StandardController con = new ApexPages.StandardController(u);
ProfileTabUserController ext = new ProfileTabUserController(con);

System.assertEquals(u.Id, ext.subjectID);
System.assert(viewingMyProfile);

String cancelPage = ext.cancel().getUrl();
String savePage = ext.save().getUrl();

}
}
Sonam_SFDCSonam_SFDC
Could you please share the error message you are recieveing when trying to save the test class..


Stephanie AkinStephanie Akin
Error Error: Compile Error: Variable does not exist: viewingMyProfile at line 14 column 15

Sorry about that.
Sonam_SFDCSonam_SFDC
This error message is coming up reason being the test class doesn't have the viewingMyProfile field defined like you have it in your actual class: 
public boolean viewingMyProfile { get; set; }


Stephanie AkinStephanie Akin
So how would I fix this? Sorry I am very new to apex. 
AndrewFisher_TGPAndrewFisher_TGP
did anyone solve this ?