Monday, November 28, 2011

Chatter Overload: Chatting in Multiple Orgs

How do people deal with collaborating in multiple Chatter clouds with different groups of people

I'm not sure there's a best answer for this, but for what it's worth here's how I deal with membership in three Chatter clouds.

My three Chatter clouds:
  • Enterprise org: for internal use only
  • App org: also for internal use
  • Higher Ed Cloud: created by the Salesforce Foundation for inter-institutional collaboration

To start my day, I login to both the Enterprise org (hosted on NA1) and the App org (hosted on NA11) with my default browser. This allows me to click links in the Chatter digest and notification emails to go directly to the Chatter thread to post a response. For the Higher Ed Cloud, I'm connected using Chatter Desktop, which allows me to post quick responses to new posts and comments because the composite Chatter feed is sorted by both Post & Comment Date.

I suspect that for those of us who aren't as fortunate to work in orgs that are hosted on different servers, we have to rely on the Chatter Desktop feature that allows fast switching between different orgs, which works pretty well in my opinion.

But in the end, how much collaboration one can handle across all media depends on what each of us value. Setting up Chatter to send notifications on every post and comment anywhere may not be a commitment suitable or desirable for everyone.

Friday, November 25, 2011

Using IsPersonAccount Field in Account Triggers

Great news! It looks like the IsPersonAccount field is always available for use in Apex triggers, without the need to retrieve the field values using SOQL!

The following test was used to reach this conclusion (in Winter '12):
  1. Create a trigger that activates or fires before/after insert, before/after update and before/after delete.
  2. Add code to the trigger to check every record in Trigger.new and in Trigger.old with the following assertion: System.assert(accountInTrigger.get('ispersonaccount') != null);
  3. Create a test method to insert, update and then delete an Account.
  4. Verify that the test passes.

Optionally, one can also use the following code in the trigger to take a deeper look at the basic information that's always available, depending on what caused the trigger to fire:
System.debug('Trigger.new = ' + Trigger.new);
System.debug('Trigger.old = ' + Trigger.old);

Tuesday, November 22, 2011

Link to FAQ in SGHE Customer Support Center

To address a FAQ issue similar to the absence of direct RPE links in the SunGard HE Customer Support Center described in a previous post, hopefully the utility below will give users a way to share FAQ's more quickly and effectively.

FAQ #:
URL:

Thursday, November 17, 2011

Notification of New Comment on Idea in Salesforce

A quick Google search for "salesforce idea new comment notification" revealed that I wasn't the only person frustrated with how un-social Ideas are in the Social Enterprise. My only consolation is that at least it is possible to setup an Email Alert to notify the Idea Creator that a new comment was added, only when a new comment is added and not when the Idea is modified.

To do this, we just need three things:
  • Workflow Rule: Alert Creator on New Comment
  • Email Alert: Idea: New Comment Added
  • Email Template: Idea: New Comment

Workflow Rule: Alert Creator on New Comment

Object: Idea
Evaluation Criteria: Every time a record is created or edited
Rule Criteria: LastCommentDate > LastModifiedDate

Email Alert: Idea: New Comment Added

Object: Idea
Recipients: Record Creator

Email Template: Idea: New Comment

Subject:
New Comment ({!Idea.NumComments}) on Idea: {!Idea.Title}
Plain Text Body:
A new comment has been added to your Idea: https://na11.salesforce.com/ideas/viewIdea.apexp?id={!Idea.Id}

Please use Chatter or email to notify others who may also wish to respond to the comment, since you are the only person who received this notification.

Chatter: https://na11.salesforce.com/_ui/core/chatter/ui/ChatterPage

Thank you

Thank you, everyone who talked about this problem and frustration in the online communities:

Revolutionizing Unit Tests in Salesforce with Public Test Classes

One of the coolest features in Winter '12 for any organization that uses Apex has to be public test classes.

Why? One main reason: Public test classes combined with a tool like HardBoil will revolutionize unit testing in Salesforce!

Imagine a world where functional users (yes, functional users!), not developers, actually setup all of the unit tests through an interactive process that...
  • Saves developers countless hours of writing boilerplate code.
  • Drastically reduces human error in staging test data, checking pre-conditions and asserting post-conditions.
  • Produces clean, self-documenting and easy-to-read test code.
  • And trains functional users to learn the data structures and respect data quality, all at the same time!

Here's the immediately achievable concept: Create a single, public test class (perhaps using HardBoil) called something like EnterpriseTestDb. Then, all one has to do is start every test method by instantiating EnterpriseTestDb as follows:
// Stage test data.

EnterpriseTestDb db = new EnterpriseTestDb();

// Set test parameters.

Account largeAccount =
        db.getAccountByName('Acme Corporation');

Contact mainContact =
        db.getContactByName('John Doe');

...

The best parts about all of this, again, is that...
  • Not a single second of developer time was needed to create potentially hundreds of test records that can support every single unit test in the entire org!
  • Functional users learned the data structure by setting up all of the test data for their developers!

And the long-term concept? Automatically generating test methods already setup to check pre-conditions and assert post-conditions, thereby allowing developers to simply fill in the code in each test method to move from the pre-condition to the post-condition.

In short, I can't wait for this new world to arrive.

Friday, November 11, 2011

Link to RPE in SGHE Customer Support Center

Getting to RPE's in the SunGard HE Customer Support Center seems to be a bit of a chore, and there isn't an intuitive way to grab a URL that can be shared with colleagues or the SGHE community. Hopefully this post will give users a way to share URL's conveniently and get to the content faster.

RPE #:
URL:

Monday, November 7, 2011

assertEquals Method for Multi-Select Picklist Values or Other Delimited Values

I couldn't find a way to easily assert that two multi-select picklist values are identical, especially considering that 'value1;value2' really should be considered equal to 'value2;value1'.

To fix this, I wrote an auxiliary class System2 that has a custom assertEquals method that asserts two Strings contain the same delimited values.

The code is verified by checking the following cases in an associated test class:

s1s2result
pass
afail
afail
aapass
aa;bfail
a;bafail
a;ba;bpass
b;aa;bpass
a;bb;apass
a;b;cc;a;bpass
b;a;ca;b;cpass
a;b;ca;b;c;dfail
a;b;c;da;b;cfail

Saturday, November 5, 2011

JavaScript Hack to Render Red Bar for Required apex:selectList

I'm surprised that Salesforce doesn't support rendering apex:pageBlockSectionItem elements with the same red bar that identifies a required element.

All I wanted was for ...


... to look like ...


So, for consistency of developing a Visualforce page that has a consistent look-and-feel, I came up with a script snippet that seems to work to add the red bar to any apex:pageBlockSectionItem with the dataStyleClass set to "requiredData".

Here's the code:
/**
 * Add the Salesforce "required" appearance to an 
 * input cell.
 *
 * @param td The input cell to give a "required" 
 *           appearance.
 */
function addRequiredAppearance(td) {
    
    // Construct the wrapper div that goes inside 
    // the td.
    
    var requiredInputDiv = 
            document.createElement("div");

    requiredInputDiv.setAttribute(
            "class", "requiredInput");
    
    // Construct and append the div that renders 
    // as the red bar.
    
    var requiredBlockDiv = 
            document.createElement("div");

    requiredBlockDiv.setAttribute(
            "class", "requiredBlock");

    requiredInputDiv.appendChild(
            requiredBlockDiv);
    
    // Move each child from the td inside the 
    // wrapper div.
    
    while (td.firstChild) {
        requiredInputDiv.appendChild(
                td.removeChild(td.firstChild));
    }   // while (td.firstChild)
    
    // Append the wrapper div inside the td.
    
    td.appendChild(requiredInputDiv);
}   // function addRequiredAppearance(td)

// Iterate through every marked element to add 
// the required appearance.

jQuery(".requiredData").each(function (i) {
    addRequiredAppearance(this);
});

With the desired apex:pageBlockSectionItem elements marked, this code adds the red bar to compliment a Visualforce input element that has the required attribute set to "true".

As mentioned in the discussion thread, Salesforce may at any time change the way they render required fields. Since this was only tested in Winter '12, the hack may not work in a later release if applied as-is. However, the concept should still hold true, and as long as the function is modified appropriately all should be well.

Note: This hack uses the jQuery library for selecting marked elements.