Apex, SOQL, and salesforce.com

Peter Coffee got in touch the other day, not from eWeek, where he was for 18 years (counting its previous incarnation as PC Week), but from his new gig as Director of Platform Research at salesforce.com. There was a period when I wrote reviews for PC Week and worked closely with Peter. We had a good laugh about how the general readership media tends to forget the installed base when they talk

Peter Coffee got in touch the other day, not from eWeek, where he was for 18 years (counting its previous incarnation as PC Week), but from his new gig as Director of Platform Research at salesforce.com. There was a period when I wrote reviews for PC Week and worked closely with Peter.

We had a good laugh about how the general readership media tends to forget the installed base when they talk about software market share, and how that played out in the Windows Vista rollout coverage. Peter has blogged about that issue here.

I suspect that his real reason for contacting me, however, was to tell me about the new Apex programming language launched in preview in January at salesforce.com. Peter certainly knows about my less-than-secret identity as Mr. Computer Language Person. The Apex programming language is not to be confused with the existing salesforce.com Apex platform. So let's explain a bit.

First, salesforce.com: it is at heart a Web-based customer relationship management (CRM) service, aimed at sales force automation, partner relationship management, marketing, and customer service. Apex is both a platform and programming language for for customizing and integrating CRM, as well as developing and deploying brand-new applications. The Apex platform runs at salesforce.com.

There are about 500 Apex applications listed at The AppExchange, including things that have very little to do with CRM, like DreamTeam, a project management and team collaboration application. I happen to know that DreamTeam was developed using DreamFactory's tool set; James Borck reviewed those tools for InfoWorld in 2004. But back to Apex.

Salesforce.com says that:

"Apex is the first on demand programming language and platform, and represents a powerful new tool for developers interested in building the next generation of business applications. With Apex, a whole new breed of on demand applications is possible, featuring sophisticated processes and business logic, entirely on demand and without software."

Now, that "without software" part has me puzzled, but let's just write it off as marketing hype. Basically, salesforce.com is releasing their internal Apex development language to the development community. Apex is a language reminiscent of Java that has embedded SOQL queries, and is described here. Apex applications run on saleforce.com servers.

Here's some sample Apex code from the Apex wiki:

// Define a trigger for the Lead object, and set it to
// fire on the insert and update events
trigger leadDupCheck on Lead(before insert, before update) {
	
	// Make sure the email and zip code fields are not null
	if (Trigger.new.Email != null&& Trigger.new.PostalCode != null ) { 
		// Query for all leads that have the same email and zip code
		// as the new lead 
	    	Integer dupCount = [select count() from Lead WHERE email = :Trigger.new.Email 
	    		AND PostalCode = :Trigger.new.PostalCode ];

	    	if ( dupCount > 0 ) { 
			// Lead exists, so display an error message
	    	 	Trigger.new.email.addError('Lead is a duplicate');
	    	} else { 
	    		// No dup is found, so let the processing continue
	    	}
	 }  	
}

Note the select query defined here inside the square brackets. That's an embedded SOQL (Sforce Object Query Language) query. It looks a lot like normal SQL, but it operates on salesforce.com fields and objects, not SQL database fields and tables, and it can't do joins or order the result set by specific fields.

That's about as much as I can say about this today. For more information about SOQL, you might want to start here.

Copyright © 2007 IDG Communications, Inc.

How to choose a low-code development platform