Showing posts with label Salesforce Tips. Show all posts
Showing posts with label Salesforce Tips. Show all posts

Sunday, February 5, 2012

A comment on formatting formulas and validation rules in Salesforce


This blog is in response to a question posted on the LinkedIn Salesforce group at:
The post lost all formatting and one point being made in my comment was using indentation for clarity so this blog is being posted to help make the point.

The question posted by Katherine was:
Validation rule to make products and Schedules necessary at a certain stage
When the stage reaches X, Y, or Z, sales reps are required to enter products and schedules. Before these stages, products and schedules are not required. Does anyone know how to write a validation rule for this?

My response was:

There seems to be some question about the syntax in the sample validation rule. For those that are interested I thought it might be useful to explain what is going on in the simplest English I can. It is useful to explain from the inside out so first the CASE statement:

Salesforce compares the StageName in the sequence given in the CASE. If any of the values match the StageName then the CASE returns a 1. If none of the values match, then the CASE returns 0. This CASE returns numbers and the enclosing AND function requires a Boolean value (True or False) so the =1 is appended to the CASE statement which Salesforce compares to the result of the CASE. Note: The = sign can mean different things in Salesforce and in this case it is a comparison and not an assignment. If the case returns 1 then the result is True, otherwise it is False.

For clarity the CASE segment of code can be rewritten as (orange reflects difference from original code):

IF (

     CASE(

           StageName,
           "Perception Analysis",1,
           "Proposal/Price Quote", 1,
           "Negotiation/Review", 1,
           "Closed Won", 1,
           0
    ) = 1, True, False
) ,…

In the solution Katherine presented, the IF statement is implied in Salesforce and is shown in shorthand notation.  This type of shorthand is convenient for the programmer but is totally unreadable by anyone who has to support the code later.

In the NOT segment:
If the Opportunity is new or already has an Opportunity Line Item then the result of the NOT function is False.

With the two inner components defined then the AND operation becomes apparent.

For further clarity, the entire validation rule is rewritten with indentation. Note the comments explaining what the =1 does and the logic of the Not segment does.  Since writing comments negates any advantage of shorthand notation it is better if you don't use implied code.  I have decades of programming experience and this use of the Case statement was totally unfamiliar to me. The colored text in the following segment is only for clarity in this blog.

AND (
     
CASE
           StageName
          "Perception Analysis", 1,
         
"Proposal/Price Quote", 1,
         
"Negotiation/Review", 1,
         
"Closed Won", 1, 
          0
    ) = 1, /* Here the = sign is a comparison operator and returns True if any of the CASE Values match the StageName */


/* The next block returns True if Opportunity is neither New nor has an Opportunity Line Item */ 
     NOT (
         
OR (
               
ISNEW(),
               
HasOpportunityLineItem
          )
     )
)

Unfortunately Salesforce strips off extra spaces to save storage space so once the rule is saved you will lose the indentation. I always write complex rules like this in a text editor and use tabs to indent and then copy and paste into the rule editor. You won't see the indentation when viewing the rule but you do see it when you edit it.
I hope that adds clarity to how the validation rule works and useful tips in making your code more readable.

Teno



To find out more about our services visit us at www.quickezlearning.com 

Tuesday, November 29, 2011

Getting started with Salesforce Visual Flow Designer


Salesforce Visual Flow Editor was Beta released in Spring 2011 as a simpler method for developing work flows in Salesforce.  The tool is intuitive and easy to use if you have a fundamental knowledge of programming concepts.  Visual Flow Designer requires connection to your Salesforce.com Sandbox Org, Developer Edition Org or Production Org.  The designer tool is free but using the Flows in production requires a subscription.  Your salesforce.com sales rep can give you subscription rates.


Pros and Cons
Pros Cons

  • Easy to learn
  • Simpler to learn than Apex
  • Quick Prototyping tool making it easy to evaluate business processes before committing to custom coding
  • Self Documenting. The flow details can be saved as a word document
  • Create Wizards to break data entry and sales processes into smaller chunks

  • Subscription rates can be expensive if there are more than a handful of users. For larger teams total customization may be less expensive
  • Inexperienced Programmers may have some difficulty
The Visual Flow Editor is available as a desktop application or in the cloud.  The cloud based version doesn't have all the features of the desktop version but To decide which version is appropriate for you can look at the comparison table at:
https://na3.salesforce.com/help/doc/en/vpm_designer_migration.htm


To get started with the desktop version download the Flow Designer manual at: http://www.salesforce.com/us/developer/docs/firefly/salesforce_flow_designer.pdf.   The instructions on how to download the desktop version is in the "Download the Flow Designer" section.

The cloud based Visual Flow Designer Implementation Guide is available at: https://na3.salesforce.com/help/doc/en/salesforce_vpm_implementation_guide.pdf
There you will find a brief section on "Creating a Flow" which is how to start developing the first flow.


In this sample Order Entry Flow the user is prompted for the account name and if the account exists then the user is prompted has the option of updating the account or creating a new Opportunity and adding products.  If the Account doesn't already exist in Salesforce then the user will be prompted for the new account information.  The user will not have to remember the process because they are stepped through it.


Order Entry Flow Diagram from Desktop Visual Flow Editor
If you would like training or information on using the Visual Form Designer and Flows in Salesforce or any other part of Salesforce go to our web-site at http://www.quickezlearning.com/Salesforce.html