Creating the Controller

Now that you have configured ScreenSteps, you need to create a controller and a page in We will begin by creating the Controller for the Visualforce page.

IMPORTANT: This must be done in a sandbox organization and then deployed to production.

Navigate to your Setup Area

Remember that this must be in your sandbox organization.

Navigate to your Setup Area

Navigate to Apex Classes Page

Navigate to Apex Classes Page

From the menu, expand Develop and click on Apex Classes.

Create a New Class

Create a New Class

Click on the New button to create a new class.

If you don't see the New button it is because you are in your production organization, not a sandbox organization.

Paste In ScreenStepsLiveRemoteLoginController Code

Paste In ScreenStepsLiveRemoteLoginController Code

In the code field (1) paste the code that appears below. Make sure to replace the string INSERT_REMOTE_AUTH_TOKEN_HERE in the code with the remote authentication token you copied in the previous lesson.

After pasting in the code and inserting your token, click the Save button (2).

public class ScreenStepsLiveRemoteLoginController {
    public string md5String {get;set;}
    private string ssliveToken = 'INSERT_REMOTE_AUTH_TOKEN_HERE';

    public ScreenStepsLiveRemoteLoginController () {
        // UserInfo does not expose the email address
        String theUserName = UserInfo.getUserName();
        User activeUser = [Select Email From User where Username = : theUserName limit 1];
        String theEmail = activeUser.Email;
        String theOrgName = ''; //UserInfo.getOrganizationName(); (not available in apex page)
        String theReturnToURL = ApexPages.CurrentPage().getParameters().get('return_to_url');
        String theTimeStamp = ApexPages.CurrentPage().getParameters().get('timestamp');
        String theStringToHash = UserInfo.getFirstName() + UserInfo.getLastName() + 
        theEmail + UserInfo.getUserId() + theOrgName + this.ssliveToken + theTimeStamp;
        Blob keyblob = Blob.valueof(theStringToHash);
        Blob key = Crypto.generateDigest('MD5',keyblob);
        md5String = encodingUtil.convertToHex(key);

The Test Class

Here is the APEX code for an accompanying test class.

private class ScreenStepsLiveRemoteLoginControllerTest {
    static testmethod void testSSLiveRemoteAuthToken() {
        ScreenStepsLiveRemoteLoginController test = new ScreenStepsLiveRemoteLoginController();
        System.assert(test.md5String != '');


Jenna Weiner

I'm getting an error with the code. I copied and pasted directly from here into a new class and then pasted in the token as directed.

When I attempt to save, this is the error I get:
"Error: Compile Error: line 5:50 no viable alternative at character '
' at line 5 column 50 "

Screencapture here:

I tried looking through the code to see if I was missing something and noticed a discrepancy between the screen capture showing the class and the code ready to copy.

Here's the difference:

Trevor DeVore

Thanks Jenna. I've updated the code and added the missing ")".

Jessica Miller

I ran the test class and it showed an 81% code coverage. I'm not a developer so I don't know a lot of technical knowledge but I know that the higher the better. Is there any reason why it's 81% and is there any way to increase that? is that just the code that was written? Thanks

Trevor DeVore

@Jessica - to be honest, I don't know why it only reports 81%. Initializing the controller calls all of the code so I'm not sure what else the test could do. I'm not a Salesforce expert so there may be an addition to the test that would give you 100% coverage. I just don't know what that would be.

Gorav Seth

Very strange indeed. I just ran the test in my sandbox and got 100% coverage (just realized i had not deployed the test when i rolled it out...).

Test class is exactly as above, as is the code, i've just replaced 'INSERT_REMOTE_AUTH_TOKEN_HERE' with my actual auth token as looks like you have as well.

Add your comment

E-Mail me when someone replies to this comment