In the previous post, we looked at using the standard (button-click) way to create a new child record using Publisher Actions. Pretty basic stuff. Using Visualforce to create a custom action is a bit harder. Let's start with the documentation. The PDF provided by clicking on the link in the Actions screen (Account action is an example) has nothing about Visualforce. Searching in the Help & Training section yields a page Creating Visualforce Pages to Use as Custom Publisher Actions, but I can't see where that page is found in the help tree on the left side of the page. Interestingly, to find correct code (because the item above has a misprint) I had to go to Customizing Case Feed with Visualforce (PDF). Let's set up our use-case and see what we can do with a Visualforce publisher. As before, we want to create a Task from a Case. The […]

There are many reasons to use Maps in Apex triggers. Sometimes I want to make a List of Contacts, but I want to pull each one by its ID. This is a good reason to abandon the List and to make a Map<id, Contact>. (Some will prefer to use Map<string, Contact>, and that is okay too.) This is how I used to populate a Map<id , Contact> of all Contacts at Accounts in a trigger: This takes time and uses script statements, and in a big org/app, we want to minimize both. Here’s my new way: It’s pretty simple, and it works well. It also keeps code clean. More astute readers will note that this is similar to the Trigger context variables trigger.oldMap & trigger.newMap, which populate a map of the trigger records keyed to their record ids.

Workflow is great. I can simply and declaratively make changes, and can easily update things like email templates, criteria, tasks, etc. without using Eclipse and writing/running unit tests. Sometimes, however, workflow isn’t enough; we need to use a trigger. Today, I had a use-case that when a DateTime field is filled, a contact (identified via a lookup on a parent object – so a grandparent record) should receive a notification. That’s easy enough to do with a ISCHANGED(DateTimeField__c) workflow criteron, but the Email Alert can’t “find” the contact. A trigger is necessary. Here’s how I coded the trigger: I’ve left out a lot of parts here, but I hope that the main bit of using Trigger.oldMap to find the old value and compare it to the new one comes through. Happy coding!

How would you display your Contacts with upcoming birthdays? I’ve seen people use “Birthdays This Week,” “Birthdays This and Next Week,” and other reports to display the list. I’ve also seen requirements for showing a person’s next birthday, to trigger an automatic email to each Contact on his/her birthday. Let’s see how it’s done: Next, use Batch Apex to send an email daily to all people where Next_Birthday__c == date.today(). Easy! Now we can put this into a report and a dashboard showing the next “n” birthdays. Sure, it’s possible that more than n people will have a birthday on a given day, but at least you know that the emails will go out to each of them! If you want to see everyone with birthdays in a certain range, make a custom report and click through from a dashboard or a custom link. Enjoy!

I've seen a lot of coders put the following into their custom Visualforce controllers: I've decided that I don't like this approach. It feels too much like a URL hack, and though I'm sure that it will always work (meaning that salesforce.com will never change its way of referring to a record by /<recordID>), I'd like to suggest a different method that may use more resources, but will leverage standard controllers, possibly future-proofing the application: What do you think? Does anyone have coding-style tips to share?