Introduced by Salesforce in their Summer 2013 release, I’m sure by now that most of you have heard something about publisher actions. If you haven’t, or you’d like to learn more about best practices and customization potential, there are plenty of articles that cover this already. The Future is Now: Taking your Chatter Publisher Actions Mobile by Cloud for Good and Publisher Actions – Not Just Creating Records by Bob Buzzard are two resources that I have found particularly helpful.

So why am I writing this blog post if there’s so much great information readily available? There are certain limitations to publisher actions that I want to address, as well as provide solutions for getting around them. And, of course, I’ll link to ideas from the Salesforce IdeaExchange so that perhaps one day this post is no longer valid.

Publisher Actions do not play nice with record types

Consider this scenario: you have an object with five different record types and you want to create a publisher action so that your Salesforce users can quickly and easily create records of that object on the fly.

Here’s the catch: you can’t add the record type field to the publisher layout. A publisher action must be tied to a single record type.

This means that if you wanted to offer the ability to create a record of each of those five types, you would have to create five different publisher actions. And, given that Salesforce recommends a maximum of nine actions per layout (including standard actions), you can see why this is not an optimal solution.

The Workaround

Step Four: Add the action to the global layout (Build → Create → Global Actions → Publisher Layouts)and/or other objects’ layouts as desired.
Step Five: Implement the following trigger code on the object that is being created as a result of the publisher action, replacing instances of Object__c with the API name of the object.
trigger ObjectTrigger on Object__c (before insert) {
   // Grab record type information for the object
   Map<String, Schema.RecordTypeInfo> objectRecordTypes
       = new Map<String, Schema.RecordTypeInfo>();

   Map<String, Schema.RecordTypeInfo> recordTypeInfosTemp
       = Schema.SObjectType.Object__c.getRecordTypeInfosByName();

   for (Schema.RecordTypeInfo recordTypeInfo : recordTypeInfosTemp.values()){
       String recordTypeName = recordTypeInfo.getName();

       if (recordTypeInfo.isAvailable() && recordTypeName != ‘Master’){
            objectRecordTypes.put(recordTypeName, recordTypeInfo);
       }
   }
   
   // Loop through all new records being created
   for (Object__c obj : Trigger.new) {
       // If the custom record type field is set, and does not match the current
       // record type assigned to the record, change the record type to match.
       if (objectRecordTypes.containsKey(obj.Object_Record_Type__c) &&
           obj.Object_Record_Type__c != obj.RecordType.Name) {
           
           obj.RecordTypeId =
               requestRecordTypes.get(obj.Object_Record_Type__c).RecordTypeId;
       }
   }
}
Step Six: You’re all done. Test it out!
Vote for this idea on the IdeaExchange: Ability to select record type when using a Publisher Action

Global publisher actions don’t know the context in which they are being created

Unfortunately, the Contact lookup record isn’t going to be automatically filled in when you instantiate that action from a Contact detail record. Bummer!

The Workaround

It’s kind of annoying that you have to do that, right? Well, never fear – there’s an idea for this, too: Default Lookup Fields in Global Actions

How are you using publisher actions?

We’d love to hear how your organization is using publisher actions. Have you run into any limitations that we haven’t covered here? Have you done something awesome that you’d like to share with us? Let us know by leaving a comment below!