Skip to main content


Showing posts from May, 2014

Get SOSL covered during Apex Test Execution.

Why my SOSL returning no data during testing?? I created sample data, I saw it in log.I swear but why it return no data? Why? Why? The hair drop one by one...the wrinkle become finer and finer.She stay quietly facing her laptop.She did not notice that her age is multiplying hastily.. . . . Stop all the drama, let see the point here.The possibility why SOSL not returning data during Apex Test Execution is because Salesforce designed it that way! WHAT!!! Yes, to ensure test class run in predictable way they decide to not return data when you use SOSL. To ensure that test methods always behave in a predictable way, any  Salesforce  Object Search Language (SOSL) query that is added to an  Apex  test method returns an empty set of search results when the test method executes. If you do not want the query to return an empty list of results, you can use the  Test.setFixedSearchResults  system method to define a list of record IDs that are returned by the search. - more info.

Making the private access modifier visible during test execution.

Whenever I got error  like below during test execution, I will go directly to the class and change the access modifier from private to public .It is not proper because each access modifier serve different purpose, so it is not quite acceptable to modify it just to get PASS for testing.Seem unacceptable but I did it a lot of times. *Evil smile* But I accidentally find proper solution for this.I posted it in my company site, but I m thinking to share it here.We can use @TestVisible ... @TestVisible everyone .I don't  notice since when it available, but I just noticed it yesterday. Shame! Well, let's start experiment it.I am using free edition sandbox to test this.You can find this free sandbox here . This is my class, notice the private stuff.Private variable and method. public class MyClass { // Private member variable @TestVisible private static Integer recordNumber = 1 ; // Private method @TestVisible private static

How to save email thread in GMail into PDF?

This is very easy.I found it when I try to print email thread.This function is there since very long time but I just recognize it today.(-_-)Y Use the Print icon at the top of the email to print/save as .pdf the whole email thread.If you want to print one email, then use the Print in the sub menu. Okey bye.Happy Friday.

Why we need to use XmlStreamWriter?

Sometimes we [maybe only me] choose the simple method to achieve something.Well, if the objective is done, what else we need to think. Actually I just want to write about XMLStreamWriter.Some code that I reviewed using simple method to generate XML, which is by appending the string.Well thinking that I going to be safe,I just proceed appending the string like example below. Example String xmlStr = ' < user xmlns:i = "" > ' ; if ( displayName != null ) xmlStr += ' < displayname > ' + displayName + ' </ displayname > ' ; if ( Group != null ) xmlStr += ' < group > ' + groupName + ' </ group > ' ; xmlStr += ' </ user > ' ; It goes well after quite some time until one day ,a user shout out about an error. 500 : There was an error deserializing the object of type bla bla.. Whenever a programmer face error, we will google it =) .I