Become a Formula Ninja

59
Become a Formula Ninja Become a Formula Ninja Math not your thing? Stuck in a functionality rut? Join us to learn a few key tips and tricks for using Salesforce MVPs to write kick-butt formulas. Walk away with actual formulas that you can immediately put to use.

description

Math not your thing? Stuck in a functionality rut? Join us to learn a few key tips and tricks for using Salesforce MVPs to write kick-butt formulas. Walk away with actual formulas that you can immediately put to use. NOTE: This session is Community-Led: created BY the Salesforce community FOR the Salesforce community

Transcript of Become a Formula Ninja

Page 1: Become a Formula Ninja

Become a Formula NinjaBecome a Formula Ninja

Math not your thing? Stuck in a functionality rut? Join us to learn a few key tips and tricks for using Salesforce MVPs to write kick-butt formulas. Walk away with actual formulas that you can immediately put to use.

Page 2: Become a Formula Ninja

Safe harborSafe harbor statement under the Private Securities Litigation Reform Act of 1995:

This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.

The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of intellectual property and other litigation, risks associated with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended July 31, 2012. This documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.

Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

Page 3: Become a Formula Ninja

Introductions & Agenda

• Steve Molis

• Jared Miller

• Mark Passovoy

• Francis Pindar

Page 4: Become a Formula Ninja

Steve MolisSteve MolisSalesforce Administrator, Epsilon@SteveMoForceSalesforce Administrator, Epsilon@SteveMoForce

Page 5: Become a Formula Ninja

Formula Ninjas

• The Island of Misfit Toys, Formulas, Fields, and Functions• Using $User to create dynamic Reports and List Views

Page 6: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and Functions

ISNEW()

$User

Opportunity: IsClosed

Opportunity: IsWon

Page 7: Become a Formula Ninja

Using a Validation Rule to prevent new Accounts during Lead Convert

Business Requirement• Prevent user from creating new Accounts but allow them to

convert Leads to new Contacts and Opportunities

Solution• Use a Validation Rule to block new Account create.

Fields Referenced (optional)• $Profile.Name

• $Role.Name

• $User.Id

Function Used• ISNEW()

Page 8: Become a Formula Ninja

Using a Validation Rule to prevent new Accounts during Lead Convert

Formula: AND( ISNEW(), $Profile.Name <> “Inside Sales User")

Page 9: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and FunctionsField: IsClosed Boolean field located on the Opportunity object, automatically set by Opportunity Stage.

Use: Validation Rule to ensure users update Close Date on Open Opportunities.

AND( IsClosed = FALSE, CloseDate < TODAY (), $Profile.Name <> "System Administrator")

Page 10: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and FunctionsField: IsWon Boolean field located on the Opportunity object, automatically set by Opportunity Stage.

Use: Validation Rule to ensure users update Loss Reason (custom field) when an opportunity is Closed/Lost.

AND (IsClosed =TRUE, IsWon = FALSE,ISBLANK(TEXT( Loss_Reason__c)))

Page 11: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and FunctionsFields: IsWon, IsClosed Use: Formula(Text) field to display the “summarized” Opportunity Status in List Views, Reports and Dashboards.

IF(IsWon = TRUE , "Won",IF(IsClosed = FALSE , "Open","Lost"))

Page 12: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and Functions

Page 13: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and Functions

Page 14: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and Functions

Page 15: Become a Formula Ninja

Using $User to create dynamic Reports and List Views

Page 16: Become a Formula Ninja

Using $User to create dynamic Reports and List Views

Business Requirement• Dynamically show in a list view, all activities that were created by the user logged in, not just activities that were

owned by them

• Users can easily see activities that are owned by them with the ‘My Activities’ list view

Solution• Evaluate the CreatedBy User.Id field and compare it to the current User.Id to return a simple True/False result.

Fields Referenced• CreatedById

• $User.Id

Function Used• IF(logical_test, value_if_true, value_if_false)

Page 17: Become a Formula Ninja

Step 1: Creat custom field, ‘CreatedBy$User’ Field Name: CreatedBy$User

Datatype: Formula

Return Type: Number, 0 decimals

Formula: IF(CreatedById = $User.Id , 1, 0)

Page 18: Become a Formula Ninja

Step 2: Create the Dynamic Report or List Now just add a simple filter:

When using this field, no more cloning and editing reports for each user! Just change the running user.

Page 19: Become a Formula Ninja

CreatedBy$User: Result

Page 20: Become a Formula Ninja

The Island of Misfit Toys, Formulas, Fields, and Functions

Opportunity: TotalOpportunityQuantityHasOpportunityLineItem

OpportunityProduct: HasRevenueScheduleHasQuantitySchedule

Page 21: Become a Formula Ninja

Jared MillerJared MillerSenior Project Manager, Configero@jaredemillerSenior Project Manager, Configero@jaredemiller

Page 22: Become a Formula Ninja

Formula Ninja

• Jared Miller• Configero• Co-Leader of the Tampa User Group• Known to troll the twitter and #askforce

Page 23: Become a Formula Ninja

Formula Ninja

• Use the ABS function to give your dates more flexibility• Use the LEN function to improve data quality• Formula Talk – My favorite formula tips

Page 24: Become a Formula Ninja

Date Flexibility: Using the ABS Function

• Business requirement

• Due to shift scheduling, a contract end date may be within a few days (plus or minus) of the actual end date

• Not all early ends, are actual early ends, however, an early end would need to be tracked differently

• Solution

• We will give the user flexibility on “early end” by giving them a plus or minus on the end date

• Fields referenced

• Scheduled End Date

• Actual End Date

• Function used

• ABS(number)

Page 25: Become a Formula Ninja

Creating the Validation Rule

• Create your 2nd Date field – in our case, it is Actual End Date• Rule Name: Actual End Date Near Scheduled End Date• Formula: ABS(Scheduled_End_Date__c-Actual_End_Date__c )>7• Error Message: Actual Contract End Date is not valid.

Page 26: Become a Formula Ninja

Creating the Validation Rule

Page 27: Become a Formula Ninja

How the ABS Function works

• From Help & Training• Calculates the absolute value of a number. The absolute value of a number is the

number without its positive or negative sign.• Example

• 9/18/2012 – 9/12/2012 = 6• 9/18/2012 – 9/28/2012 = -10

• ABS(9/18/2012 – 9/28/2012) = 10

Page 28: Become a Formula Ninja

Further validate information – text fields

• Business requirement

• Users are filling in a text field with 1 character in order to bypass an ISBLANK Validation Rule

• Using an “other” value in a picklist

• Solution

• This information is important so we will be using the LEN formula to count the number of characters

• Fields referenced

• Payment Terms

• Special Payment Terms

• Function used

• LEN(text)

Page 29: Become a Formula Ninja

Typical “Other” scenario and validation rule

• Using our payment terms example

• Putting a “1” will not meet the validation rule criteria

Page 30: Become a Formula Ninja

How we can use LEN to get better data

• Using our payment terms example

• Putting a “1” will not meet the validation rule criteria

Page 31: Become a Formula Ninja

Creating the Validation Rule

• What you already have: 2 fields (picklist and text)• Rule Name: Special Payment Terms must have Terms• Formula:

AND(ISPICKVAL(Payment_Terms__c, "Special Payment Terms"),LEN(Special_Payment_Terms__c)<5)

• Error Message: If Payment Terms are “Special Payment Terms”, please enter the terms.

Page 32: Become a Formula Ninja

Formula Talk – My favorite formula tips

• CASESAFEID (id)– Converts a 15-character ID to a case-insensitive 18-character ID

• ISCHANGED(field) – Checks the field to determine if the value has been changed. This is useful in validation rules and workflow rules.

• When thinking through your formula – or when you are working on a complex formula – use comment tags

• /* comment here, Name, Date */• Comments will count against your character limit and byte size

Page 33: Become a Formula Ninja

Mark PassovoyMark PassovoyConsultant, Appirio

@markpassovoy

Consultant, Appirio

@markpassovoy

Page 34: Become a Formula Ninja

Formula Ninja

• Mark Passovoy• Appirio• Will respond directly to @ mentions on Twitter• Answers maniac (but not as much as @SteveMo)

Page 35: Become a Formula Ninja

Everyday use of Formulas• Validation Criteria• Workflows Criteria• Approval Process Entry Criteria• Formula Field

• Simple Examples:• Amount > 1• Number of Employees < 10

Page 36: Become a Formula Ninja

1.

2.

3.

4.

Real Life Examples

Page 37: Become a Formula Ninja

Concept: Dynamic formulas using only variables

• Business Requirement• Users must apply different logic to Opportunities from each of the 5 regions that the company operates in.

• IT does not have the bandwidth to update formulas in Salesforce in a timely manner and is continually backed up with requests to update criteria or logic of formulas, workflow, validations, approvals, etc.

Page 38: Become a Formula Ninja

Solution• Create an object to compare data for each region against

• Formulas will reference relationships between the Opportunity and the custom Region object without using any actual values

• User will select region on creation of Opportunity, or process can be automated with a trigger

• Benefit – Formulas can be updated easily, without access to Setup, if important

Page 39: Become a Formula Ninja

Solution

Page 40: Become a Formula Ninja

Validation Rule

• Hard-coded numeric values

• Completely dynamic, no hard-coded values

Page 41: Become a Formula Ninja

Formula Field

• We created a formula field to determine the overall risk of an Opportunity

• This field will give the Opportunity one of 5 possible values, depending on the information in the Opportunity and the selected Region

Page 42: Become a Formula Ninja

Approval Process

• We created an Approval Process to approve Opportunities

• It will use information from the Opportunity, as well as the related Region for entry criteria and step criteria

Page 43: Become a Formula Ninja

Formula Talk – My favorite formula tips

• & - Can concatenate text and merge data together to make a string

• HYPERLINK( “00U/e?retURL=%2F006x0000001T8O,&what_id=“ & Id, “Create Event”)

• BR() – Will insert a line break in a text string. Make sure to surround this function with &

• & BR() &

• IMAGE() – Can insert an image from Salesforce into a field, and even be used in Email templates

Page 44: Become a Formula Ninja

Francis PindarFrancis PindarTechnical Consultant@radnip

http://uk.linkedin.com/in/francisuk

Technical Consultant@radnip

http://uk.linkedin.com/in/francisuk

Page 45: Become a Formula Ninja

Formula Ninja

• Francis Pindar• Freelance technical consultant• Hang out on Answers (never able to keep up with @SteveMo!!)

• Apex & VisualForce developer discussion boards• London Salesforce user group & developer user group

Page 46: Become a Formula Ninja

Business Requirements

• Reduce the risk of negative social media storms by using social influence

• Ability to prioritize cases based on social influence• Use social influence to aid marketing activities to target influential customers

Page 47: Become a Formula Ninja

Web-To-Case Solution

Page 48: Become a Formula Ninja

IMAGE Function

Syntax:

IMAGE(image_url, alternate_text [, height, width])

Text Formula Field:

IMAGE(“http://socialimage.herokuapp.com/getImage.php?NetworkScreenName=“+Twitter__c+”&NetworkPlatform=twitter&KloutAPIId=4abgffbxzyg7sufuvpjqsx9w”, “No Image”)

Get API Key from:http://developer.klout.com/

Page 49: Become a Formula Ninja

Business Requirement

• Make reports more actionable.• Allow data to be SEEN without READING• Ability to see Account metrics from account records without the need to run reports.

Page 50: Become a Formula Ninja

Solution

Page 51: Become a Formula Ninja

Solution: Google Charts

Page 52: Become a Formula Ninja

Solution: Google Charts

• Formula image function can call any chart URL

• Google chart wizard offersdynamic build environment

• Easily add merge fields into the chart URL

Page 53: Become a Formula Ninja

Solution: Google ChartsSearch Google “Image Chart Wizard”

Page 54: Become a Formula Ninja

Solution: Google Charts

Page 55: Become a Formula Ninja

Solution: Google Charts

Value

Label

Page 56: Become a Formula Ninja

Solution: Google Charts

Value

Label

IMAGE("http://chart.apis.google.com/chart?chxl=0:|negative|average|positive&chxt=y&chs=250x125&cht=gm&chd=t:" + TEXT(Overall_Satisfaction_Percentage__c) + "&chl=" + TEXT(Overall_Satisfaction_Percentage__c) +"%&chma=0,0,5", "No Image Available" ,125,250)

&chd=t:82&chd=t:" + TEXT(Overall_Satisfaction_Percentage__c) + “

Page 57: Become a Formula Ninja

Google Charts: Special Notes / Limitations

• HTTP / HTTPS Mixed Content• Specify Height & Width on Image Function• Google Chart Wizard is NOT SSL Encrypted

Page 58: Become a Formula Ninja

Steve MolisSteve Molis

Salesforce Administrator, Epsilon

@SteveMoForce

Jared MillerJared Miller

Senior Project Manager, Configero

@jaredemiller

Mark PassovoyMark Passovoy Francis PindarFrancis Pindar

Consultant, Appirio@markpassovoy

Technical Consultant@radnip

Page 59: Become a Formula Ninja