Redkite News & Opinion

Redkite announces appointment of two senior cloud technologists to its leadership team

By Brennan on March 21, 2011

March 21, 2011 – New York, NY – Redkite, a New York-based Salesforce strategy and implementation partner, announced today the appointment of two senior cloud technologists to its leadership team. Derek Tsang has joined as Redkite’s Head of Technology. Vincent Ip will lead Redkite’s research and product development efforts.

As Head of Technology, Derek will oversee Redkite’s technology delivery methodologies, and its development and data services teams. Derek will also be responsible for building out Redkite’s offshore delivery team and extending the company’s capabilities into new cloud technologies.

Derek joins Redkite from Fujistu Consulting, where he was Director of Technical Consulting. Since 2004, Derek has led some of the most complex integrations for Salesforce’s enterprise financial services clients and has been responsible for some of the earliest back-office integrations with Salesforce’s API and custom UI-level integrations.

Vincent Ip will head up Redkite’s research and product development efforts. Vincent joins with more than 6 years Salesforce development experience on over 20 Salesforce implementations with Fortune 500 companies. Vincent has been working with the Redkite team as a hired gun since 2009. He was the lead architect of Redkite’s successful in|force Connector, which enables Salesforce users to view LinkedIn® profile data directly within Salesforce contact pages. The in|force Connector has been in the top 5 most downloaded Appexchange products since its launch in November.

“We are very excited for Derek and Vin to join the Redkite leadership team,” said co-founder Brennan Burkhart. “These guys have been pushing the threshold of custom development and integration with Salesforce for the past 6 years. Their combined experience is truly unmatched in our industry. Both will play a key part in our strategy to deliver high-end strategy, design and implementation services to our clients.”

About Redkite

Redkite is a Salesforce solution provider founded by delivery professionals who have pioneered the design and deployment of cloud solutions to enterprise clients since 2004, on more than 100 implementations for Fortune 500 companies. Redkite’s professionals have led many of the largest and most advanced implementations of Salesforce CRM in the world. Redkite proudly brings this same excellence in strategy, design and delivery to clients of all sizes. To learn more, visit us at www.redkitetechnologies.com.

Writing Salesforce Test Cases – Tips and Best Practices

By Vincent on March 20, 2011

CodeTesting

Writing test code in Salesforce.com is a necessary step in deploying code. Yes it’s a bit annoying and it sucks when someone else’s test code breaks and prevents you from deploying your code. I saw an email in my inbox from Salesforce about a free webinar on testing and Coverage best proactices, and I’ve always wanted to document some advice that I’m often passing on to other Salesforce Apex Developers when writing test cases, so here I am. I was suprised to not find many blog posts out there when i searched for “Salesforce Apex Testing Best Practices” (I did find one really good blog post at gokubi.com). Hopefully I can add to what’s out there.

Write Portable Tests

I can’t stress this point enough. It’s the top item in that gokubi article too, and YES it’s that important! When writing you should never depend on certain records being there. Even if you think, “No, i’ll make sure no one deletes this record.” One day, when someone else is going to deploy code, it’ll turn up missing.

There’s also a flip side to this. You should also not depend on tables being empty. This can happen when you’re creating code that is supporting a brand new custom object. Usually, I’ll see the test code insert records, then run it’s test case, where the new code will query records from that table and maniplate them in some fashion. This will probably work great, in Sandbox and even deploying into production, but… a month or 2 down the line where there’s more data accumulated in that table and the query no longer behaves as the test expects. No more deployments until this problem is resolved (and of course these are usually discovered when someone is deploying code).

TIP: Sometimes, you need to cheat a bit

This second point in the previous section, about not depending on empty tables, is not always a straight forward change in the test code. Lets take an example of a batch process which queries the entire table and updates a field. When testing batch code, Apex only runs one batch of the process. If you’re creating sample records in your test code, how do you ensure that the batch process will pick up your test records?

You can put in a “sort by” clause in the query to ensure the records can get picked up, but… you really don’t want to affect performance just for the sake of writing test code. I think in this case, it’s ok to cheat a little. Check the Test.isRunningTest flag and modify the query if it’s true. The code below shows an example of an implementation. The class implements a Database.Batchable interface and has a conditional test code in the start method.

global MyClass implements Database.Batchable{
    ...
    global Database.QueryLocator start(Database,BatchableContext bc){
        String soqlQuery = "Select Id, Name, MyFlag__c from Account";
        if (Test.isRunningTest()) soqlQuery += " Sort By LastModifiedDate Desc";
        return Database.query(soqlQuery);
    }
    ...
}

Don’t just write coverage code. Make asserts!

When I see test code without asserts, I always just shake my head. You really should ensure that the code you write is doing what you expect. Writing a proper test case includes creating appropriate test records, then running some code for your test, and then finally putting in place the appropriate asserts will ensure that your code is doing what you expect. It also helps you from making future changes which would break your use case. This is expecially true if you’re writing trigger code, since triggers can affect lots of other apex code and their tests.

Code Structure

ImageFor the most part, most of my test code has the following structure (see diagram to the left). This structure may be a bit obvious to most, but I like to explain it to those new to writing test code. It makes code reviews of test code go by much quicker.

A comment should be placed between test code sections. Comments are always helpful, but in the test code, a little mention of the actual use case you are testing for helps enormously!

The asterisk after the “Setup runAs User” is there because this is not always needed. Only if your code is dependant on a specific role / profile or there’s some other User attribute which you need to test your code, would you need this.

A note about using the System.runAs() block. The User object that you pass into the runAs() method does not need to be a inserted into the database. I found this out when some of my test code was deployed into an org with 0 licences free. In my test code I had inserted the user record that I was using in the runAs() block. While fixing my test code, i noticed that inserting the User record is not needed.

Write test code for your most imporant Use Cases

If you can code for all possible Use Cases for your code, that’s great, but sometimes that’s an open ended problem. At the very least you should try to write test code for the most often used Use Cases. You should also code for error cases that could potentially occur a lot. The good thing about coding for both positive and negative use cases, is that it may make you think of more odd use cases, and thus more robust code. Hopefully that will put you very close to 100% code coverage. You may need to code a few more less likey Use Cases, or even directly call some functions and properties to get to that 100% mark. It’s not always necessary to get to the 100% mark, but get as close as you can.

Add a Comment »

Editing SFDC Zipped Static Resources in Eclipse – Zip Editor

By Vincent on March 1, 2011

One of the reasons people don’t create a zipped static resource in Salesforce.com is that it’s a bit of a pain in the neck to edit their contents.

You typically have to download the file from Salesforce (if you don’t already have a current version locally), unzip, perform your edits, zip them back up and then upload back again through the UI. Or. if you were a bit more clever, you could have tried to leverage the static resource is a Force.com project in Eclipse, and tried to get the Force.com IDE to push changes up to Salesforce.

Both options are a pain in the neck if all you want to do is play with some css class definition, as you’d probably be doing those same steps over and over again.

Now, I’m sure I’m not the first one to figure this out, but getting a zip editor plugin for eclipse comes in extremely handy for this situation. I recently installed one called “Zip Editor” into my Force.com IDE (Eclipse Helios). This looks very promising, as I’m now able to view the contents of zipped resource files within Eclipse itself and even make edits directly into the zip file. Now there is a little bit of a weird workflow that I have to follow to get zipeditor to save my updates to the zip resource, but it’s not so bad and WAY better than what I was doing before!

So here’s a link to the Sourceforce project for the Eclipse Zip Editor. Let me know if you run into a better solution for editing SFDC zipped resources!

Add a Comment »

Dynamic Visualforce Bindings – ooOOOoo

By Vincent on February 18, 2011

This blog post is mainly a summary of what i just read in the SFDC Dynamic VF Bindings section of the documentation for version 21.0. Pretty cool stuff. This will allow programmers to make VF pages even more Administrator friendly (as opposed to be Developer only territory). So Dynamic Visualforce Bindings allow VF pages to be more flexible when it comes to displaying fields of sObjects and even public properties of Custom Apex Classes. Previously when working with <apex:outputField> tags and <apex:column>, you would always have to define the field name somewhere in the VF code to present it on screen. Now there’s syntax that allows you to dynamically get fields at runtime. It’s about time! So the following are example code snippets (borrowed from the documentation). which uses the new features:

Using a List of field names on an Account object

Here “fieldList” is a List<String> which contains ‘Industry’, ‘BillingCity’, ‘AnnualRevenue’.

<apex:page standardController="Account" extensions="DynRefAccFieldLister" >
 <apex:form>
  <apex:pageBlock title="Account Fields" mode="edit">
   <apex:pageBlockSection columns="1">
    <apex:inputField value="{!Account.Name}" />
    <apex:repeat value="{!fieldList}" var="fld" >

     <!-- access the account fields that are a part of the field set! -->
     <apex:inputField value="{!Account[fld]}" />

    </apex:repeat>
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>

Extending this example a little, we can retrieve the label and value separately

<apex:page standardController="Account" extensions="DynRefAccFieldLister" >
 <apex:form>
  <apex:pageBlock title="Account Fields" mode="edit">
   <apex:pageBlockSection columns="1">
    <apex:inputField value="{!Account.Name}" />
    <apex:repeat value="{!fieldList}" var="fld" >

     <!-- get the label for the field set fields this way -->
     <apex:outputText 
      value="{!$ObjectType.Account.Fields[fld].label}" />
     <apex:inputField value="{!Account[fld]}" />

    </apex:repeat>
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>

Using a List of indexes against a List of Strings

This example is mostly a copy from the documentation. Controller class contains the following properties:

public List<String> people {
 get { 
  return new List<String>{'Winston', 'Julia', 'Brien'};
 }
 set;
}
public List<Integer> iter{
 get { 
  return new List<Integer>{0, 2, 1};
 }
 set;
}

The following VF code can display the list in the 0, 2, 1 order.

<apex:repeat value="{!iter}" var="pos">
 <apex:outputText value="{!people[pos]}" /><br/>
</apex:repeat>

Using a List of keys against a Map

Similar to the one above, but using a map. Here the map is of type <string, string>, but something like a <string, Account> can also work and you would use it just like you would expect! Sample Controller code:

public Map<String,String> directorsToCountry {
 get { 
  return new Map<String, String>{'Kieslowski' => 'Poland', 
   'del Toro' => 'Mexico', 'Gondry' => 'France'};
  }
  set;
}
public List<String> keys {
 get { 
  return new List<String>{'Kieslowski', 'del Toro', 'Gondry'};
 }
 set;
}

The following VF code can display the map.

<apex:repeat value="{!keys}" var="director">
 <apex:outputText value="{!directorsToCountry [director]}" /><br/>
</apex:repeat>

Using a FieldSet against an Account object

Finally, you can use a FieldSet to define… well… a set of Fields. This FieldSet can then be iterated through in a VF page and then applied to an sObject. Here’s the example from the documentation. Here properNames is a Contact FieldSet which contains fields holding First Name, Middle, Name, Last Name ,and a Job Title field. The following VF could be used to view those fields for a specific record

<apex:page standardController="Contact">
 <apex:repeat value="{!$ObjectType.Contact.FieldSets.properNames}" 
  var="f">
  
  {!$ObjectType.Contact.Fields[f].label} 
  ({!$ObjectType.Contact.Fields[f].type}): 
  <apex:outputField value="{!Contact[f]}"/>
  <br/>
 </apex:repeat>
</apex:page>

Cool! This makes me want to create FieldSets for every ding-dang custom list i’ve ever had to write.

Performing Comparisons on Custom Labels in VF pages

By Vincent on February 2, 2011

Ran into a strange “bug” today while developing a VF page.

This VF receives parameters through the URL which the VF Controller class parses out and stores in a class variable. The VF page also has an <apex:outputPanel> section which is rendered if the URL parameter equals a specified Custom Label. The code looks like the following:

Example URL:
https://na#.salesforce.com/apex/MyPage?param1=paramValue

Example Custom Label Definition:
Custom Label Name : MyLabel
Custom Label Value : paramValue1

Example Visualforce Page:


<apex:page controller="MyController">
 <apex:outputPanel rendered="{!ctrlParam1=='$Label.MyLabel'}">
  <apex:outputText value="Hello, World!"/>
 </apex:outputPanel>
</apex:page>

Example Controller Class:


public class MyClass{
 public String ctrlParam1{get; private set;}
 public MyClass(){
  map<string> params = ApexPages.currentPage().getParameters();
  ctrlParam1= params.get('param1');
 }
}

With the configuration details setup as above, the <apex:outputPanel> is not rendered. More specifically, the code rendered="{!ctrlParam1=='$Label.MyLabel'}" evaluates to false.

Playing around a bit with this code, and a lot of head scratching, netted me the following code that does work:

rendered="{!ctrlParam1==$Label.MyLabel}"

(No quotes around the Custom Label). I guess $Label.MyLabel is a variable in and of itself, and not a replacement string as I assumed that it was. Wish Salesforce.com Help and Training had more sample code. Grrr..

Add a Comment »

« Newer News Stories | Older News Stories »