Apr 29, 2012

Using Dates in Dynamic SOQL

I often use dynamic SOQL. It's a very useful when trying to satisfy multiple scenarios in a single query, or when building a query from pieces you don't have until runtime. It gets a little hairy keeping the code clean with large queries, but if you use consistent formatting and indentation, the code ends up fairly readable.

When it comes to using dates in dynamic SOQL, you have to convert your dates and datetimes to strings with a very specific format. I can never remember that format and that area of the documentation is very light, so I always end up trying to find where I used it last or searching online. The problem with searching online is that there are several wrong examples high on the search ranks (at least when I search for it).

So, here is the correct syntax if you ever need to use dates in dynamic SOQL...
  • date: myDatetime.format('yyyy-MM-dd')
  • datetime: myDatetime.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'')

Here is an example that uses both a date and datetime in a dynamic SOQL statement:
list<contact> c = Database.query('SELECT id FROM SomeObj__c WHERE SomeDatetime__c > ' +
myDatetime1.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'') + 
' AND SomeDate__c < ' + 
myDatetime2.format('yyyy-MM-dd') + 
' LIMIT 10');

Apr 22, 2012

Handy Inline JavaScript and CSS Hover Popup for Salesforce Lists/Tables

I tried to use my handy CSS hover popup in a table that was included within a component that also included a partial page refresh action (using rerender). The popup was working fine when the page was initially rendered. However, as soon as a partial refresh event occurs, the component loses track of the CSS that is included in the main page (static resource). Not sure why that happens. I tried everything I could think of, but could not get the component to remember the stylesheets after the rerender.

So I decided to recreate the same functionality with javescript and inline CSS. That way I am not giving the component the opportunity to lose the stylesheet from the parent page. I simplified the code to be as compact as possible, and you don't need a static resource or adding the visualforce stylesheet tag to the hosting page. What makes this work is the onmouseover and onmouseout events in the link as well as the z-index style in the link and the div inline styles.


  
    
      {!c.Name}
    
A couple of final notes:
  • The div needs to follow the end outputlink without any white space because some browsers treat white space as elements on the page, which makes the javascript nextsibling not work.
  • If the popup detail does not have carriage returns or special formatting use the an outputtext inside the div like in the example below. If you want to preserve carriage returns, use the following inside the div instead: <pre>{!c.Description}</pre>

Apr 2, 2012

Cliff Notes From Peter Coffee's Phorum Presentation

I attended the cloud computing conference Phorum last week, and thought that it was very well organized and attended for a first time conference. My main goal in going was to hear Peter Coffee, VP & Head of Platform Research at salesforce.com, who presented in the morning, was part of a panel in the afternoon, and closed the conference with a panel featuring 3 demo pit companies. This was the first time I've seen Coffee talk, and I was not surprised that he was very well spoken, articulate, and charismatic (Salesforce execs definitely have a type...). He was also friendly and personable when we chatted during one of the breaks.

Coffee's presentation (available on slideshare) was titled "Clouds of Revolution - Reinventing the (social) Enterprise". The main takeaway was that evolution is not a good enough process and that companies must undergo a revolution - replacing their current technology/processes altogether instead of adding and patching existing ones. Coffee argued that innovation is continuing its hockey stick path so adding improvements to existing systems still puts you at a disadvantage. I think it is an interesting premiss that, in my opinion, has not been traditionally embraced by Salesforce. However, Salesforce's recent big acquisitions and it's new mobile strategy seem to support this idea.

When it comes to the cloud, Coffee says that it is a reality and that enterprises should jump in fast and embrace learning and change (revolution not evolution). He was less than impressed with private clouds. In his opinion the label "private cloud" is used by CIOs so they can get funding for modernizing their existing data centers.

Coffee thinks that the next revolution is the social enterprise (not surprising coming from a salesforce.com exec). He gives convincing examples of real world and hard to solve problems that are not likely to be solved by adding technology alone (evolution), but require connectivity as an effective solution (social revolution). He also argues that social is a reality that enterprises cannot ignore, and that proactively providing secure social enterprise eliminates the inevitability of uncontrolled social usage within the enterprise. He also makes the arguments that social makes expertise rise to the top where the traditional org chart didn't. However, Coffee also acknowledged the yet unsolved data overload problem of social tools by saying that empowered social employees are not necessarily more efficient, and that algorithms and visualization must be added to convert data to curated info.

When talking about security in the cloud, Coffee argues that the cloud is more secure than alternatives but regulators and customers don't understand that. He believes that cloud security issues are sometimes more related to regional regulation as opposed to an IT issue. He continued to say that European regulators are sometimes more focused on the physical location of data than the technology that secures it.

Coffee also thinks that whitelisting is a better approach to security than the more standard blacklisting. He provides the Salesforce AppExchange as an example, and says that companies that went through the process thought it was a great learning experience. I have to say that my experience in this area is very different - I feel that the learning opportunities in the AppExchange listing process are small and are drowned by the long and tedious overall experience.

I hope this is a good summary for those of you that missed the conference. Again, the conference definitely exceeded my expectations, and was supported by an excellent speakers and panelists . I'll certainly plan to go next year, especially if Coffee is scheduled to talk again!