• Sunbeam11
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hello,

 

I am assuming that SFDC usernames are unique acorss all org.

 

That said, Is following scenario even possible ?

 

On a Personal Developer Edition Org I have a user name - john.smith@company.com 

on a Dev box (test.salesforce.com) for a client, I also have same username -  john.smith@company.com

 

Keep in mind I am not talking about the portal user name. These 2 are SFDC platform licensed users.

Hello,

 

I am assuming that SFDC usernames are unique acorss all org.

 

That said, Is following scenario even possible ?

 

On a Personal Developer Edition Org I have a user name - john.smith@company.com 

on a Dev box (test.salesforce.com) for a client, I also have same username -  john.smith@company.com

 

Keep in mind I am not talking about the portal user name. These 2 are SFDC platform licensed users.

Can someone help me figure out why this test class is failing?

 

The class was needed for a visualforce page that Customer Portal users will be hit with when they initiate a Live Agent Chat. The page is called a Pre-Chat page. I couldn't get access to the Customer Portal User's account name using the fields from the User standard controller.

 

Here's the Class:

public with sharing class NICP_Functions 
{

    public String getAccountName(){return strAccountName;}
    private User u;
    string strAccountName = '';
    
    public NICP_Functions(ApexPages.StandardController controller) 
    {
        this.u = (User)controller.getRecord(); 
        strAccountName = u.AccountId;
    }

}

 Here's the test class:

@isTest
private class TestNICP_Functions
{
    static testMethod void testPreChat()   
    {
        // PAGE REFERENCE
        Profile p = [SELECT Id FROM Profile WHERE Name =: 'Customer Portal Manager Standard'];
        User u = [SELECT id FROM User WHERE ProfileId =: p.Id AND IsActive = true AND AccountId != null LIMIT 1];
        PageReference ref = Page.NICP_PreChat;
        Test.setCurrentPage(ref);         
        NICP_Functions controller = new NICP_Functions(new ApexPages.StandardController(u));
        string an = controller.getAccountName();
    }
}

The error I get when I test the execution:

Class TestNICP_Functions 
Method Name testPreChat 
Pass/Fail Fail 
Error Message System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: User.AccountId 
Stack Trace Class.NICP_Functions.<init>: line 22, column 1
Class.TestNICP_Functions.testPreChat: line 22, column 1 

 

 

Thank you very much!