Showing posts with label workaround. Show all posts
Showing posts with label workaround. Show all posts

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:

Sunday, March 20, 2011

Comparison of null to Integer Always Returning true

I ran across an interesting phenomenon when comparing null values to Integer values on Visualforce pages: The comparison always returns true!

  1. null < 0 evaluates to true
  2. null = 0 evaluates to true
  3. null > 0 evaluates to true

It appears that it's best not to compare null values to Integers, since the result is effectively useless.

ISBLANK(String) Returning false When String.length() Returns 0

I discovered this with version 21.0 of the Salesforce API: When a String's length is 0, the ISBLANK(String) Visualforce function will actually return false instead of true.

Visualforce Developer's Guide, Version 21.0 describes the ISBLANK function as follows:

Determines if an expression has a value and returns TRUE if it does not. If it contains a value, this function returns FALSE.

A search for ISNULL in the documentation returned no real results, which makes me wonder if ISNULL has been unofficially deprecated in favor of ISBLANK.

So, it appears that the only way to know for sure whether a String input has been blanked out is to use the length method and compare it to 0.

Tuesday, January 18, 2011

Comparing Salesforce Record ID's in Visualforce

Strangely enough, the Visualforce comparison operator does not work when comparing a 15-digit record ID with an 18-digit one. The workaround I concocted is to use a very specific Boolean property in my controller extension to perform the comparison instead, since I really wanted to avoid using any kind of custom ID conversion code that may become invalid in future releases.

public Boolean isCitizenshipCountryUnitedStates {
get {
return stdCtrler.getRecord().get('Citizenship_Country__c') == unitedStatesCountryId;
}
}

The situation I have is that I want to compare the Country of Citizenship specified on an application record (for custom object Application) to see whether the applicant is a U.S. citizen. Country of Citizenship is a Lookup(Country) field, with Country also being a custom object.

Without hardcoding the Id for the United States country, I defined a unitedStatesCountryId property as follows:

 public Id unitedStatesCountryId {
get {
if (unitedStatesCountryId == null) {
List matchingCountries =
[SELECT Id FROM Country__c
WHERE Name = 'United States'];

if (matchingCountries.size() > 0) {
unitedStatesCountryId = matchingCountries.get(0).Id;
}
}

return unitedStatesCountryId;
}

set;
}

When I evaluate the expression {!Application__c.Citizenship_Country__c = unitedStatesCountryId} in my Visualforce page, the expression always returns false. When digging a little deeper, I found that Application__c.Citizenship_Country__c was returning 'a0DT0000006NIDM' while unitedStatesCountryId was returning 'a0DT0000006NIDMMA4'! Visualforce appeared to be comparing the two values as Strings and not as Ids.

Finding no Visualforce-native solution, I had to go the route of creating the isCitizenshipCountryUnitedStates property in my controller extension. Needless to say, this quirk in Salesforce does not make me happy.