Thursday, January 20, 2011
String Keys for Apex Maps Are Case-sensitive
I discovered today that String keys for Apex Maps are case-sensitive. Apparently the Strings "johndoe" and "JohnDoe" are not equal when being compared to see if the Map contains a key.
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) {
ListmatchingCountries =
[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.
Labels:
Apex,
comparison,
controller,
extension,
Id,
Salesforce,
Visualforce,
workaround
Tuesday, January 4, 2011
Deleting Characters (a.k.a. Backspacing) through SSH in PuTTY
I've been annoyed consistently by a quirk with SSH, PuTTY, Unix and sudo where pressing the backspace character prints a
To delete characters, all one has to do is press either...
^?
on the terminal instead of deleting the previous character. Then, to my amazement today, I stumbled upon a way to delete characters through SSH in PuTTY without messing with any terminal configurations!To delete characters, all one has to do is press either...
- Shift+Backspace; or
- Right Arrow
I assume this works with Terminal in Mac OS X or Linux as well, but I have not yet tried. Gone are the days now when I have to retype a 80+ character command just because of a single, silly typo...
Subscribe to:
Posts (Atom)