Spring in Seattle
Last Updated on Sunday, 6 December 2009 11:49 Written by Steve Friday, 30 March 2007 08:33

Apex is revolutionary
Last Updated on Thursday, 29 March 2007 03:10 Written by Steve Thursday, 29 March 2007 03:00
I can’t stop giggling. My first 25-line Apex coding project will replace a 400+ line S-Control. Seriously, it’s blowing my mind a bit.
Here’s the code:
trigger HouseholdCheck on Contact bulk (before insert) {
for (Contact c : Trigger.new) {
if (c.ONEN_Household__c == NULL) {
String RecognitionName;
RecognitionName = c.firstname + ' ' + c.lastname;
ONEN_Household__c hh = new ONEN_Household__c (
Name=RecognitionName + ' Household',
Recognition_Name__c=RecognitionName,
Recognition_Name_Short__c=c.firstname,
MailingStreet__c=c.MailingStreet,
MailingCity__c=c.MailingCity,
MailingState__c=c.MailingState,
MailingPostalCode__c=c.MailingPostalCode,
MailingCountry__c=c.MailingCountry
);
insert hh;
c.ONEN_Household__c = hh.id;
}
if (c.AccountId == NULL) {
Account[] account = [select id from account where Name = 'Individual'];
c.AccountId = account[0].Id;
}
}
}
I won’t paste in the 400 line HTML form and code that it’s replacing…
All the new code does is create a Household for a Contact when you’re creating a Contact. If you’ve selected a Household, it doesn’t create one. It also adds the Contact to the Individual account if you haven’t picked a different one.
Simple, huh?
But it’s been really hard to do in Salesforce.com before Apex. We had to build a custom Contact creation form that was seriously 400+ lines long.
Not only does it replace my custom data entry screen, it fixes all sorts of problems. We couldn’t use Quick Create because a Household wouldn’t be created when the Contact was–now it will. We couldn’t let people sync Outlook contacts for the same reason–now we can. When a Contact is created anywhere, anyway, by anyone, the trigger will fire, and they will have a Household.
That also makes the integration story better. Our Plone integration won’t have to care about the Individual Account. It won’t have to worry about Households. We’ll have an Apex trigger like this one that will take care of our crazy business rules behind the scenes.
I knew Apex was coming and that it would make this kind of thing possible. But actually learning enough of the language to write this code in under two hours was more than I could have hoped for.
Apex is revolutionary. These guys are definitely on to something.
Learn MoreLazyweb: Zoho Writer for Salesforce.com one-off mail merges
Last Updated on Monday, 26 March 2007 09:52 Written by Steve Monday, 26 March 2007 09:52
Ismael wrote a post about how all Office 2.0 startups should join the Appexchange as a way to raise visibility and drive business. So, I’d like to give him and Zoho.com an idea for a nice Appexchange product that would be really easy for them to write.
I like the Salesforce.com Word integration that lets you create one-off mail merges from records in Salesforce.com. It makes thank you letters, and other non-batch documents easy to knock out.
It only works in Windows with MS Word, however. I’d like to be able to do one-off mail merges on any platform. So why not do it with Zoho.com?
Zoho Writer doesn’t appear to allow mail merging from a Zoho Creator database,
so building this functionality in a single product might make
a lot of sense. Zoho Writer would then have a plug-in architecture to
merge from any API enabled database. Pretty powerful.
A working integration with Salesforce.com would be pretty easy to build. It would be easy to put a Zoho Mail merge button in the activity history section of all your records. The code it would call would have to do this:
- Show an interface where you get to select on Contact/Lead and one other object to reference, prefilling those fields with the current object you are coming from.
- Show your Zoho.com Salesforce.com templates and allow you to select one. This would require you to log on to your account, which could be handled in different ways.
- Grab the Zoho.com template you select, find all the merge tokens, replace them with the correct data, and open a new Zoho.com document with the merged text.
- Optionally create an Activity in Salesforce.com to record the mail merge.
For building out templates, they would need to create:
- A way to flag documents as Salesforce.com templates. Could be as simple as a tag, like “SaleforceTemplate”.
- A way to insert merge tokens into a Zoho.com document. These are text elements like “{!Opportunity.Amount}” so could be done by hand (not user friendly) or through a simple UI driven by the Salesforce.com API. This second approach would require a user to specify their Salesforce.com user account–something that tons of partners have already built in some fashion. Even more generalized, a user could have multiple online database accounts that they could pull merge tokens from.
- Add support for Opportunity Line Item, which iterates over all the Products associated with an Opportunity. This is really important for itemized invoices and the like.
This would be immediately helpful to me and my users who don’t have access to Windows and Word, with additional benefit for people in distributed setups where Office 2.0 is already in place, or makes a lot of sense.
I’m sure Zoho.com and Ismael have lots of thoughts about what a Zoho/Salesforce integration looks like. Here’s my two cents on one feature that I’d love to see.
Learn More