Skip to main content
30 votes

What are the compiled costs of each Formula function

Notes: There are a lot of functions to check, so building a complete list will take a bit of work. I've made this a community post so others can contribute if they like. Salesforce changes the ...
20 votes
Accepted

Remove whitespace before and after the string dynamically?

use trim() method of String class Returns a copy of the string that no longer contains any leading or trailing white space characters. String s1 = ' Hello! '; String trimmed = s1.trim(); ...
Oleksandr Berehovskyi's user avatar
19 votes

Remove whitespace before and after the string dynamically?

I like using normalizeSpace() instead of trim() for such scenarios, as it also handles repeated white space. normalizeSpace() Returns the current String with leading, trailing, and repeating white ...
Raul's user avatar
  • 18.8k
19 votes

How to display Picklist Label, instead of Picklist API in a Formula Field

Unfortunately this feature does not seem to exist yet. Vote for this Idea: Allow Picklist Value Labels in Formulas Spring '17 brought "API Names" to picklist values so that integrations can ...
Adrian Larson's user avatar
  • 150k
12 votes
Accepted

Process Builder - Add Minutes,Hours to Event End Date

Use the Formula like Now() + (60/24/60) Give your required minutes in first 60. If you want for 10 minutes to be added, Give like Now() + (10/24/60) Then you will get the 60 minutes added to the ...
Subhash's user avatar
  • 1,716
12 votes
Accepted

How to calculate duration between two dates(in months and days) using formula field?

Neither formula will be perfectly correct. Depending on your tolerance, you might consider: (date1 - date2) / 30.43685 This gives you the number of days divided by the number of average days in a ...
sfdcfox's user avatar
  • 495k
12 votes
Accepted

How to query the data that has been modified in last 30 MINUTES

The easiest way might be to make the following Minutes_Since_Modified__c formula: (NOW() - LastModifiedDate) * 24 * 60 Then to query for it: SELECT Id FROM Account WHERE Minutes_Since_Modified__c <...
Adrian Larson's user avatar
  • 150k
11 votes
Accepted

Formula field is not working as expected

Assuming your formula was copied directly from salesforce.com, the problem has to do with "Smart Quotes." Salesforce formulas don't recognize “ and ” as actual quotation marks. Try using the following:...
sfdcfox's user avatar
  • 495k
11 votes
Accepted

Is There a Limit to Lightning Formula Parameters?

Yes, it's a known bug/limitation of Expression Operators. You can only evaluate two parameters in and and or expressions. You'll probably want to consider setting an attribute evaluated by your ...
sfdcfox's user avatar
  • 495k
11 votes
Accepted

How to reference Choice Value in formula instead of its label?

For whatever reason, as noted here, you seem to get the label if you refer to the field, but you get the value if you pass the field into a record element/variable. As @Mitesh stated, you should be ...
Kris Goncalves's user avatar
9 votes

Differentiate Production/Sandbox Instance?

You should be able to write a formula that will expose a line saying "Production" or "Sandbox" by using your production id from Administer->Company Information. There are ...
Carlos Naranjo's user avatar
9 votes
Accepted

How can I ensure that a field is blank for some account types, and mandatory for others?

You should be able to piece this one together. Here are the functions you'll need: OR(logical1, logical2...) and replace any number of logical references with the expressions you want evaluated. AND(...
Adrian Larson's user avatar
  • 150k
9 votes

How to render after an if statement with visual force page

In this specific case, it would be marginally more efficient to use BLANKVALUE, just as you would with a formula: <apex:outputText value="{!BLANKVALUE(item['text_1'],item['text_2'])}" /> A ...
sfdcfox's user avatar
  • 495k
9 votes
Accepted

How to differ between rollup-summary and formula fields using APEX Schema functions?

You can tell because when you describe a Rollup Summary Field, its describe returns null when you call getCalculatedFormula(), unlike a Formula Field. system.assertEquals(null, rollupDescribe....
Adrian Larson's user avatar
  • 150k
9 votes
Accepted

Formula Field - Case Function

If function will work inside the case statement in formula You can do like this:- CASE( sa_nket__case_text__c , '00', 'Member', '02', 'Member', '03', 'Member', '99', 'Member', '23', IF( ISBLANK(...
sanket kumar's user avatar
  • 15.4k
9 votes
Accepted

Validation rule Scheduled Apex

Scheduled Apex runs in system mode, but that's not the same as running with a context user that is a system administrator. In system mode, FLS and CRUD aren't enforced against you (you control the ...
David Reed's user avatar
  • 93.2k
9 votes
Accepted

Can someone confirm if I've identified a bug in Salesforce regarding formula fields?

I believe that this is expected. The reason why is that Salesforce presumes the default value for a field when no object is present. That can make all the difference when you do something like adding ...
sfdcfox's user avatar
  • 495k
8 votes

Error: Function ISCHANGED may not be used in this type of formula

You can only use ISCHANGED in the following cases: Assignment rules Validation rules Field updates Workflow rules if the evaluation criteria is set to Evaluate the rule when a record is: ...
sfdcfox's user avatar
  • 495k
7 votes

How Can I Tell the Day of the Week of a Date?

For reference, an Apex code version of the modular division approach is: public static Integer dayOfWeekNumber(Date aDate) { return Math.mod(Date.newInstance(1900, 1, 7).daysBetween(aDate),7); } ...
Rick Coates's user avatar
7 votes
Accepted

How to Implement "Else If" In Merge Field?

Remember that the IF function syntax is IF(logical_test, value_if_true, value_if_false). So if you want an "else if" clause, put another IF function in place of value_if_false. IF(condition1, 'value ...
Adrian Larson's user avatar
  • 150k
7 votes
Accepted

How to truncate zeroes from an account number

Here it is, most simple way to achieve this IF( BEGINS(Customer_Account_No__c, "6"), TEXT(VALUE(RIGHT(Customer_Account_No__c, LEN(Customer_Account_No__c)-1))), "") Converting Text to ...
Santanu Boral's user avatar
7 votes
Accepted

What is the difference between single or double quotes in a formula?

They exhibit the same behavior. One thing I do in Visualforce formulas and carry over into formulas elsewhere is that I use double quotes to emphasize the difference between Apex and what I am working ...
Adrian Larson's user avatar
  • 150k
7 votes
Accepted

Using ISCHANGED(ISPICKVAL(StageName)) in Process Builder Formula

Your first formula was probably the closest. Here's the revised version. The IsPickVal function requires two parameters, separated by a comma. The IsChanged function requires one parameter, the field ...
sfdcfox's user avatar
  • 495k
7 votes
Accepted

Performance-wise, is it better to query a relationship field or a formula field?

If the formula is literally: Account.Name Then you get the use of indexes, such that: WHERE AccountName__c = 'Demo' WHERE Account.Name = 'Demo' Are identical in performance. If you use any sort ...
sfdcfox's user avatar
  • 495k
7 votes
Accepted

Difference in minutes between two datetime fields

Difference b/w two date time would never be 0 until you have exact date time value. So in your case, you can resolve your issue either by changing the return type of formula field to TEXT or NUMBER(...
Pragati Jain's user avatar
  • 1,570
7 votes
Accepted

Validation rule - created date < FIXED DATE

Unlike SOQL, formulas don't accept date literals. You'll need to construct your Date values using either the DATE() function : The DATE() function returns a Date value, given a year, month, and day. ...
David Reed's user avatar
  • 93.2k
7 votes

Getting a formula validation error, can anybody spot where I am off?

Your last IF block has no value_if_false. What you have IF ( ts2__Job__c.Days_Search_Open__c >= 91, "91+", ) What you need IF ( ts2__Job__c.Days_Search_Open__c >= 91, &...
Adrian Larson's user avatar
  • 150k
6 votes

Is is possible to have an automatic width or height on a photo in an image formula?

Well actually I've found a way doing it! Using -1 as the value for the value you want to be set equivalently to css "auto". e.g: IMAGE(url,"alt text", 100, -1) It will actually make the browser ignore ...
Tzahi Serruya's user avatar
6 votes

Is there a list of Salesforce images that can be used in custom pages and formula fields?

Well, I was also referencing those links earlier and found that some of them no longer work and others don't have all the images. You can still look at all the CSS files provided by Salesforce and ...
Anshul's user avatar
  • 2,629
6 votes
Accepted

Do calculations on child records properties for master record

Just create a custom field on the parent object using the rollup summary data type. The field creation wizard will walk you though it. Create a formula field on the child "Total Amount" (quantity * ...
sfdcfox's user avatar
  • 495k

Only top scored, non community-wiki answers of a minimum length are eligible