Saturday, June 28, 2014

Avoid Flow Trigger Errors Associated With User Records

With Summer '14, more users are finding more to processes to automate with Flow Triggers.  This is just a note to let you know that the User record does not behave like other records when used in a Workflow rule.  It can cause "MIXED DML OPERATION" errors, and simply report that your "trigger failed to execute the flow with version ID 30111000000..." or something very similar.

A time-based trigger can be set to fire behind another trigger.
This happens when a Workflow Rule triggers by creating or editing a User record and also executes a Flow Trigger to manipulate records from other types of sObjects rather than the User record alone.  In particular, it happens when a Workflow tries to update one of these fields on the User record as well as other sObjects like Contact or Case:
  • UserRoleId
  • IsActive
  • ForecastEnabled
  • IsPortalEnabled
  • Username
  • ProfileId
Here are some techniquess to avoid encountering the Mixed DML Operation error message:
  1. Try using a different sObject, not the User record, for Workflow Rules and Flow Triggers if you encounter the error regardless of which fields are being updated.  
  2. To update the six standard fields listed above, create two different Workflow Rules, for example:
    • Initiate the first Workflow Rule off a record other than the User record.  Use this other sOject to trigger updates to custom fields on the User record for any of the above six  fields.  You can operate User custom fields safely alongside data from other sObject records in a single workflow.  
    • A second, time-based Workflow Rule can operate on the User record alone and update the above fields based on changes to your custom versions of those fields.  This Workflow Rule only operated as a time-based trigger and only allows for field updates on the User record.  Note: do not check the box on your User-based Workflow Rule that calls for all workflows to be reevaluated.  If that box is checked, you may experience the DML error again.
  3. If you don't want to run two separate Workflow rules and must manipulate one of the User fields based on changes to the User record, don't do it in a Workflow.  Instead, create a Visualforce page to call the Flow and create a custom link on the User detail page to access the page and Flow.  Click here for information about passing record IDs to a Flow with Visualforce.  The Flow will manage each data manipulation request as a separate transaction if it is not called by a Workflow and so the Mixed DML error should not occur.
Using one of these techniques with Flow Triggers can avoid the problem of having a trigger fail to execute a flow due to mixed data manipulation errors.
 

Wednesday, June 25, 2014

Simplify With Record Types, Field Dependencies and Validation Rules

Salesforce administrators should have the goal of simplifying and error-proofing the data-entry process for Salesforce users.  This makes for happier users, fewer day-to-day problems, and better data.  But User Experience is rarely a class at administrator school.  So here are some pointers to keep in mind:
User don't want too much data or too many options.
  • For two column entry, users tend to want to see the entry progress linearly down one column, then the other, rather than zig-zagging from column to column.
  • Fewer options in picklists are easier to navigate.
  • Consistency is important for design, field naming and data entry.
  • Data entry on keyboards should require few or no mouse clicks.
  • Users don't want unnecessary options cluttering their screens.
One way to put this into practice is by making good use of record types, field dependencies and validation rules.


Record Types


Record types help users by limiting the number of fields available on the screen for any particular data.  If, for example, you have a Salesforce object called Equipment, you might want different record types for Electric Vehicle and Petroleum Vehicle because electric vehicles won't need to track gallons of gas.  Having different record types lets you customize the fields to be only what is needed for any given data set.

But record types are exclusive.  If you have Vehicle record types for Electric and Petroleum vehicles, what will users do when they need to select Hybrid?  You can simply add more record types, but at some point your list can get unwieldy if you aren't careful.

Imagine using a single object, Equipment, to track vehicles, computers and more.  If every vehicle type and every computer or mobile device type, etc., requires its own record type, the list could be endless and difficult to maintain as new equipment types become available in the future.  In this case, broader record types can be used and other database design considerations can be employed to help users view only the options they need for their data.


Field Dependencies  


For a record type of Computers, we might offer a picklist to specify whether a piece of equipment is a desktop/laptop or a mobile device.  A single subsequent picklist can offer options tailored to each device. With any two picklists, you can define a field dependency that limits the options available on the second list depending on the selection made from the first list.

For example, an Equipment object with a picklist offering Desktop/Laptop and Mobile as options, might have a single multi-select picklist with status descriptions.  You don't want Mobile device data showing up with a status of "bad hard drive", but you can remove that option from the picklist for all Mobile data by defining which options to include based on a field dependency.


Validation Rules


As useful as field depencies are, not every data entry option can be expressed as a picklist.  For other fields, validation rules can provide similar limitations.  For example, if you have two Equipment data sources for temperature, one for freezers and one for heaters let's say, the range of valid data will be different for each of them.  With a validation rule, you can provide a single field, but check that the values make sense for different kinds of data being entered.

By designing a data model that makes good use of record types, field dependencies and validation rules, you can protect your database from bad data and give users a better experience as well.  If you can eliminate extraneous options, users will not have to sift through fields and choices to get their work done, nor will they have to go back and check whether they put in a negative or positive value for that freezer temperature because the system will do all that for them and improve not only the data quality, but also the user experience.



Wednesday, May 7, 2014

Salesforce1 and Connected Apps Update

As a follow-up to a previous post about connected apps, I wanted to share information about a change with Salesforce1 as of mid-March 2014.  If you are looking for a list of users who are accessing their data via Salesforce1, the Connected Apps detail page "View OAuth Usage" option is no longer the best place to get that information. 

Looking for Salesforce1 users, look in the login history.
Salesforce1, unlike other Connected Apps (Workbench, AppExchange, etc.) removes users from the OAuth Usage list when their refresh token is revoked.  This token allows users to remain logged in to a Connected App without repeatedly providing their credentials.  Settings allow administrators to set a time for revoking the token if users should not remain logged infinitely.  When the user logs out, the access token is also revoked.

For the Connected Apps detail page, Salesforce1 users who have logged out and have no access token may not appear in the list.  The only users that will appear are those who remain logged in via their mobile devices.

You can still find out which of your users are accessing data via Salesforce1 on their mobile devices, though.  Instead of using the Connected Apps list, export the login history for your users and sort based on Application to find all of the "Salesforce1 for iOS" entries.  (Note that sorting on the Application without exporting may not group the data.)

To revoke access for users, rather than going through the "View OAuth Usage" option, you will need to make changes to the Connected Apps detail page.  In that case, you may want to change settings for user authorization and/or the refresh token. 

Thursday, April 24, 2014

How to Interview for New Skills

Someone recently asked me to recommend interview questions for a company looking to hire a Salesforce Administrator/Developer.  This question is particularly interesting for small nonprofits and companies that are looking to bring in knowledge and skills that don't already exist in the company.  How do you ask questions and judge the answers if you can't already answer the questions yourself and aren't sure what to ask?
What do your questions look like?

Consider what you stand to gain or lose by asking questions you do not understand.  For example, I was asked once if I had any experience with the "Apex Exchange".  While this sounded unfamiliar at first, I figured out that they were asking about the "AppExchange" and simply not pronouncing it correctly.  The fact that the interviewer would ask this question said a lot about what someone might expect while working there.

Here are some questions that anyone should feel comfortable asking:
  • What most helped the job candidate pass certification exams?  (Hopefully this reveals extensive and varied experience with Salesforce in the real world.)
  •  What challenges have been the most interesting in Salesforce and why?  (This may give insight into what they find challenging technically or collaboratively.)
  • And how did they find their way through that challenge?  (Hopefully they can describe a process of discovery and growth.)
  • What do they like the best and the least about the Salesforce release cycle? ( Hopefully this reveals that they re-engineer as needed to work with new features.)
It is important to hire someone who can demonstrate an ability to learn, grow and problem-solve independently as well as communicate well and understand the needs of others.  My blog post about a video, 'The Expert', shows some examples of what businesses want to avoid.

For interviewers without specific skills, the need for someone who has those skills is coupled with a need for someone who can communicate clearly and make you feel confident with their process.  If no one in-house has the technical experience, then you really have to decide if applicants have the ability to find information and solve problems independently while bringing all the stakeholders along.

Friday, April 18, 2014

Salesforce Flow Using Record IDs at the Start or at the Finish

Salesforce Flow can be combined with Visualforce pages to provide greater flexibility and automation to the user interface so that Salesforce users have fewer opportunities for mistakes. 
Racer X doesn't always like to start with the group.

 

Start

By invoking a Flow through a Visualforce page, you have the option to create a button on the particular object you intend to manipulate.  In this example, a button on the Lead object is configured to access a Visualforce page that invokes a Flow to convert the Lead.

Because the button exists on a specific record detail page, the standard controller makes the record ID accessible for the specific data being displayed when the button is clicked.  This means that the record can be converted without additional Apex code.  The Visualforce page would look something like this:

<apex:page standardcontroller="Lead" >

    <flow:interview name="LeadConversion">
            <apex:param name="thisLeadID" value="{!Lead.Id}"/>
    </flow:interview>

</apex:page>

 Finish

Finishing the Flow by bringing the user to a specific record detail page is more difficult. The easiest solution by far is to provide the information and actions the user needs as part of the Flow rather than as something they see after the Flow is finished. 

But even the complicated solution, adding Apex code to a custom Apex controller or extension to specify a finishlocation, is not too difficult.  Simple code enables Salesforce Flow to finish on record detail page. Even so, there are some considerations for defining a finishlocation:
  • Visualforce is required to specify a finishlocation and only URLs in your Salesforce instance can be specified within the finishlocation attribute on the Flow according to documentation
  • For variable finishlocations, an Apex controller is also required
  • Rather than referencing variables as part of the finishlocation, use a variable in place of a finshlocation on the Visualforce page
Here is a simple method to add to your Apex controller code to use a specific record ID in the finish location:

        public PageReference getpRefFinishLocation() {      

            String temp = 'home/home.jsp';
            if(myflow!=null) temp = string.valueOf(myflow.RecID);
            PageReference pRef = new PageReference('/' + temp);
            return pRef;

        }

Use code like the example above to access a variable, RecID in this case, from your flow and incorporate that into the URL for the page users see when they finish executing the Flow.

Friday, April 11, 2014

Provide Mobile Users with a Rich Experience Using Flexipages and Salesforce1

How do you make the most useful data available to users on a mobile device?  You may want to limit text and reduce the need for swiping and scrolling.  Think about the types of activities you are most likely to perform using your phone – texting, calling, photographing, listening to and watching or just looking.  We love the multimedia capabilities and the rich data we experience at a glance with mobile devices.  Salesforce1 provides an important new feature to help you create a more engaging and mobile-efficient interface for your Salesforce data.
Red flag understocked merchandise.

 

Flexipages


Make use of Flexible Pages, or Flexipages, to create a more engaging and mobile-efficient interface for your users by providing useful graphics and text in record lists directly off a tab.  Mobile users should be able to get as much data as possible in a glance and images can help make that possible.  For example, you can use image formulas to display graphical representations of a record’s status.  For an Opportunity, you might add an image formula to represent where in the pipeline each record happens to be.  This way, salespeople who are on the road can glance at a list of records to determine which need the most immediate attention rather than swiping and reading through a list of text.

Unfortunately, early Salesforce1 releases don’t support image formulas in the tab view.  Tab fields are determined through the Search Layout options, these are the fields users see when they select an object tab on desktop Salesforce, and image formulas have historically been useful here.  Yet the first time a user selects an object tab in Salesforce1, it won’t display images.  While this may change with later releases, there is another option available to early adopters as well.


For the most rich data experience, you can bypass the object tab using Flexipages and make data with images available with a single tap on the Flexipage tab.  Flexipage tabs access the first few fields of either a specific list view or recent items, both of which can use image formula fields.  Note that for recent items on a Flexipage, the fields come from your defined compact layout for that object rather than the familiar fields your users see in their desktop experience.


Flexipages also give you the ability to combine multiple data objects in a single list to even further reduce the tapping and swiping required for accessing the most critical data with a mobile device.  If you use the recent items list in the desktop Salesforce sidebar, you are already accustomed to seeing multiple objects in a single list, all highlighted with an informative graphic.  Replicate this type of user experience for mobile users with Flexipages.


For an example of how to create Flexipages, check out the documentation here: http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_flexipage.htm


Thursday, April 3, 2014

Don't Let Expertise Stand In The Way Of Creativity

A funny video has been making the social media rounds called "The Expert" by Lauris Beinerts.  While I find the video to be hilarious, I don't sympathize entirely with the character known as the expert, but also with the folks trying to hire him.  They have specific needs and he fails them in a multiple ways because he lets his expertise stand in the way of creativity.

A creative approach can make the impossible become likely.
Mistake #1:  He says "No" to one of their specifications.  Rather than telling them it can't be done, he should take the opportunity to ask more questions, deep dive into their requirements and find out exactly what they would like to achieve.  Maybe he is missing some other key requirements by not asking for a bigger picture of what they need.

Mistake #2:  He fails to educate the customer.  When the customer asks for something he cannot deliver, he fails to educate them about the limitations, although he does make some effort at this.  He should take the time to align their expectations with the limitations of whatever system they may be using.

Mistake #3: He doesn't offer to do more research.  If he took the time to look into their requests and came back to them with a follow up proposal, he might find some creative and interesting approaches to their problems.  Just for fun, lets look at some of their requirements:
  • Red lines from green ink? Perhaps he should try color changing markers or a system of filters and lights.  There are also thermochromatic pigments and color-shifting paints that could offer fun solutions.
  • Red lines from transparent ink?  Perhaps he should put the lines over a red background or try special magic markers.  Will the customer accept red lines cut from construction paper and colored with transparent ink?  
  • Seven perpendicular lines?  Perhaps he should investigate working in 7-dimensional space.
  • Make one of the lines a kitten?  A 1-dimensional kitten might meet their requirement, but the expert did not ask enough questions to find out.  Maybe they would rather have a combination of lines and curves?
The need is two-fold:  experts need to hone their communication skills as well as their creativity.  Experts need to be better communicators and have the patience not only to discover what the end-goal of a project really is but also to help everyone understand the project's limitations.  In addition, creativity will make any expert even better.  Take the time to explore challenges that would otherwise seem like impossibilities rather than just saying "No".  As with improvisational acting, experts in any field should strive to build on the ideas of others rather than negating them.