You need to sign in to do that
Don't have an account?

Help with test class please..
Hi all, I'm newbie in apex and visulaforce development, I have the following apex class:
public with sharing class UserAccountCtrl {
public Id UserAccountId{get;set;}
public String ErrorMessage{get;set;}
public UserAccountCtrl(){
try
{
Id userId = UserInfo.getUserId();
User us = [select Id, ContactId from User where Id =: userId];
if(us.ContactId == null)
ErrorMessage = 'The user logged is not related to any contact';
Contact cont = [select Id, AccountId from Contact where Id =: us.ContactId];
UserAccountId = cont.AccountId;
}
catch(Exception ex)
{
ErrorMessage = ex.getMessage();
}
}
}
and visualforce code:
Hi,
First of all, please go through a few documents explaining the need/way for a test class.
A few links that might help:
http://www.forcetree.com/2011/06/guide-to-writing-test-methods-for-apex.html
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
For the above class, you can use the below test coverage class:
Let me know if any questions/issues. Thanks!