• MichaelRusso212
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Are there performance differences between using components vs templates? 

Is there a way to set up portal users to be redirected to a custom error page (much like Sites allows) rather than have them see the actual exception? Is there a way to do this without setting up "try...catch" blocks?

 

 

Thanks,

 

Michael 

Hi,

 

I am trying to write a unit test for a method that inserts a record that uses the sessionId as part of the key. The sessionID is retrieved using UserInfo.getSessionId(). In my test, I invoke the method on my object that makes the insert, and then I try to retrieve that row using UserInfo.getSessionID(). However, the sessionID that is inserted from within my class is different than the one I see in my testmethod.

 

Here is the method I am trying to test: 

 

public void rateDocument() { docRating__c dr=new docRating__c (Rating__c=this.documentRating, DocumentID__c=this.documentID, Comments__c=this.documentFeedback,Rating_Session__c= UserInfo.getSessionId(),RatedBy__c=UserInfo.getUserId() ); insert dr; }

 

and here is my testmethod:

 

public static testmethod void testRateDocument() { User usr = [Select id,name,contactid from User where isActive = true and user.contact.id != null limit 1]; System.runAs(usr) { myController con = new myController(); con.documentRating=5; con.documentID='testdoc.html'; con.documentFeedback='awesomest doc ever'; con.rateDocument(); docRating__c docRating = [SELECT Rating__c,DocumentID__c, Comments__c, RatedBy__c FROM docRating__c WHERE Rating_Session__c=:UserInfo.getSessionId() AND RatedBy__c=:UserInfo.getUserId()]; System.assertEquals(docRating.Rating__c,con.documentRating); System.assertEquals(docRating.DocumentID__c, con.documentID); System.assertEquals(docRating.Comments__c, con.documentFeedback); } }

 

 

 

 

 When I run the testmethod like so, the testRunner complains that there are no rows being returned by my query into docRating__c. 

 

The way around this problem is to make the sessionId part of the class, and then use that sessionID when doing the query prior to the assertion. This is bad, however, because I don't want to have to add the sessionID to my controller and because the architecture shouldn't change to suit the tests. 

 

Does anyone know why this is happening? I thought that the sessionID might be changing as a result of the call to System.runAs(), but it doesn't. I looked at the UserInfo object before and after System.runAs, the name and userID will change accordingly, but sessionID stays the same. Regardless, the class method is being invoked from within the runAs block so that should be(?) using the UserInfo data as the testMethod.

 

Thanks,

 

Michael 

 

Since using the new release of the IDE (version 14) I get enormous amounts of debug output, no matter what log level are set. These settings seem to get ignored, the same seems to happen in the browser output when running tests.
I set the various log levels for each category, basically disabling everything except apex code, but each test case gets several thousand (!) lines of output. So the debug log only contains output for 3 test methods before all further output gets truncated.
This makes it pretty much impossible to use the output for debugging since it misses most of the other test methods and is totally bloated with information I didn't want to see in the first place.
Any ideas what's going on here? Are the log levels just broken? Anything I can do to get useful debug log output?