Skip to main content


Showing posts from 2014

Loading Test Data ... made my life easier

Hallooo... I am still here, I forgot that I have a technical blog =) Okay, I would like to share that something that maybe there for very long time, but I just utilized it recently. My organization have something that we call Financial Calendar, it is different from our normal life calendar, where by if in our normal life a new year start on every 1 January, our financial start in different month. Well, it is not big deal except in Salesforce we need to do test class, and most of our classes having logic such the object linked to calendar object, if new quarter come in populate the data etc. Last time we just use @SeeAllData=true in order to access into this object from test class,but as you and I know it is not advisable as it may lead to other issue. So we do something like this in our test class.We need to populate record for Financial Calendar in order to use it. FinancialCalendar__c c1 = new FiscalCalendar__c(); . . . The code goes down , to define the quarter.

Invalid constructor syntax, name=value pairs can only be used for SObjects (Line: 90)

If you bumped to this entry, I would like to thank you.I 'll update the content as below.Since my explanation not really helpful at previous post.You still able to view old post at OBSOLETE section below at the end of this post. I always accidentally face this exception : Invalid constructor syntax, name=value pairs can only be used for SObjects because I instantiate inner class like SObject such as below : WrapperObj obj = new WrapperObj ( paramId = a . Id , isChecked = a . Primary__c , Account = a ); While that only valid for SOBJECT.For inner class, we should use this.Without name value pair. WrapperObj obj = new WrapperObj ( a . Id , a . Primary__c , a ); public class MyExtension { //other code public void retrieveInfo (){ List < WrapperObj > listAccountObject = new List < WrapperObj > (); List < Account > listAccount = [ Select Id , Primary__c from Account where Id =: acct . Id ];

Writing sign for URL ...write signature for Google Geocoding API

I have chance to work with Google Geocoding API Salesforce of course. The requirement is to retrieve address from Google Geocoding by passing postal code.When passing postal code through HttpRequest, it should return the response in JSON.But I am not going to write how I call it in this entry.I will save it for future.*cough* So I will write on how to generate signature... Note on this limitation between free API and paid one. Users of the free API: 2,500 requests per 24 hour period. 10 requests per second. Maps for Business customers: 100,000 requests per 24 hour period. 10 requests per second. To create API you can go here .Use our own Google account.But I found out without API key also it works. See!!This is can play around with it. So I go for Maps for Business customers, what is that mean? It means , we required to have client and signature. Google will

Clone User in Salesforce

I need to create sample of users to test one of the application.It is TEDIOUS to do data entry one by one.If two still okay for me, if five ...ten...better I start  Googling. Heh...although I know the Clone feature is exist in Salesforce but I just found out that for User there is no Clone feature directly.There work around to Clone it.Someone posted an idea for Clone User, please vote it if you feel it is useful for you.I voted it already =) Vote  idea for Clone Users : Once you vote it, don't forget to read the comments.You'll be surprise a lot of suggestion of workarounds there.The entry that I wrote today was my experiment based on the workaround suggested. In order to make Clone User feature , just follow the step below: 1 - Go to Setup --> App Setup --> Customize --> Users. Add Custom Links as below. Label : Clone User Behavior : Display in existing window with sidebar Button or Link

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

Invalid_session_id when try to create project using Eclipse.

I am not sure why since yesterday I could not create project using IDE.This is my first time error and I have been creating a lot of project using this IDE before. So I google and see this interesting issue here . It mentioned that we should go to Setup --> Security Control --> Session Setting and make sure 'Lock sessions to the IP address from which they originated' is UNCHECK. Interesting, I checked the Session Setting unfortunately it already in unchecked mode.Pondering here and there and at last I restart my machine.FYI, my machine is in hibernate mode for few days.I am lazy to shutting it down, so I just set it to hibernate. Magically- after restart and create the project again , the issue won't come anymore.Is it something to do with restarting the machine?I still wondering what the scientific reason behind this but it works. So in case, you face this type of issue-you can try to restart your machine and PRAY.  See ya again.

Testing Http call out using StaticResourceCalloutMock

I was working with the Http call out stuff lately and have a chance to learn on how to execute test class on this type of class.Test class...not my favorite subject in salesforce but it is very important :). I did some googling stuff and also bump into implementation of HttpCallout mock interface-- it was like phew! But I also bumped into other option which is StaticResourceCalloutMock and MultiStaticResourceCalloutMock which seem pretty easier. Okay let's get started! What is StaticResourceCalloutMock? Built-in class used to test our callouts by specifying the response body in Static Resource. Why? Easy instead of implement code using HttpCalloutMock interface.We just create dump response file in Static Resource then instantiate the StaticResourceCalloutMock. Scenario: I have class that call webservice from other server in order to get the token.It call the webservice using Http call out.So in order to let it deployed beautifully in production , I need to get higher