Pages

Saturday, November 2, 2013

Salesforce formula size

There are 2 limitations on Salesforce formula:
1. Character length limit, contain up to 3,900 characters, including spaces and line breaks.
2. Compile size limit, formula fields are calculated using generated SQL on the backend. This SQL must not exceed 5,000 characters. This includes other referenced formula fields.

Formulas are limited to 3,900 characters or 4,000 bytes, including spaces, return characters, and comments, and can’t exceed 5,000 bytes when compiled. It’s important to understand the differences between these size restrictions and how to work around or within the constraints.


Character length limit
For this limitation, you can easily count number of characters including spaces and line breaks, with Ms Word, it is easy to count it, so you can make sure do not over it.

You can shorten long formulas in several ways. Replacing AND() with &&, for example, saves a few characters with each use, as does replacing nested IF() statements with a CASE() statement. Shorter field names and comments also make a small but significant difference in the length of your formula.

If your formula field is significantly longer than 3,900 characters, use a helper formula field.

Options for this error:
1. Move parts of the formula into other formula fields, and reference those in your main formula. The new formula fields don’t need to appear on the page layout.
Example: create new date formula called "Short__c" with formula DATE( YEAR( Membership_Start_Date__c ), use Short__c in the formula field rather than the long formula, this will reduce number the characters, but this will NOT reduce compile size for the original formula (it will even increase it, compile size do not impact by the the length of API field name)

2. Shorter API field name, example: you can have label name 'This is a long field name', by default API name will be This_is_a_long_field_name__c, but you can modify the API name to Long_field__c


Compile size limit
A formula that is less than 3,900 characters can still exceed the 5,000-byte compile size limit. When a formula is over the compile size limit, creating helper fields and shortening field names or comments doesn’t make a difference. When you reference a helper field, its compile size is added to the compile size of the formula that references it. 

Here are few option to reduce formula size issue:
  • Minimize the number of references to other fields
  • Minimize the number of times formula functions are called
  • Rethink your picklist
  • Think about the problem another way
  • If all else fails, use a workflow field update

Minimize the number of references to other fields
The most important thing you can do to reduce your formula compile size is reduce the references to other formula fields. Each time you reference a field, the compile size of that field is added to your current formula. 

Minimize the number of times formula functions are called
Try to limit use of formula fields within a formula, you can try to change from using IF() to CASE() as possible.

Rethink your picklist
You can consider of making the picklist a lookup to a  custom object with the name as the picklist value, then create a custom field on that object for the value you need to set in the formula.

Think about the problem another way
This about to simplify the formula as possible, example: introducing CASE(), MOD(), NOT(), etc

Use a workflow field update
This maybe the last option, workflow will not update value for all existing records, unless you do mass update (which this will effect Last Modified By information). But, formula in a field update have bigger compile size limitation.


Reference:



Monday, October 21, 2013

Salesforce: How to find Custom Report Type usage

User permissions needed:
* To create or update custom report types - “Manage Custom Report Types”
* To delete custom report types - “Modify All Data”

Out of the box, Salesforce provide many standard reports and standard report types, for some users, it may be sufficient, but for some cases, admin need to create new custom report type.

A report type defines the set of records and fields available to a report based on the relationships between a primary object and its related objects. Reports display only records that meet the criteria defined in the report type.

For example, an administrator can create a report type that shows only job applications that have an associated resume; applications without resumes won't show up in reports using that type. An administrator can also show records that may have related records—for example, applications with or without resumes. In this case, all applications, whether or not they have resumes, are available to reports using that type.

You can create custom report types from which users can report on your organization's reports and dashboards. When defining a custom report type, select Reports or Dashboards from the Primary Object drop-down list on the New Custom Report Type page.

But, how about deleting a report type? Yes, this is possible for user with “Modify All Data” permission (usually system admin).

You need to aware that deleting a custom report type will 
- Permanently delete the Custom Report Type (no Recycle Bin)
- Delete any reports based on the Custom Report Type (no Recycle Bin)
- Invalidate any dashboard components based on the deleted reports

So... you really need to be careful and it is always good to find out which reports are created using report type that will be deleted?

How to find those reports? Create a new report type with Primary Object = Reports
I am not going to explain how to create report type, but you can see below screenshots:


Remember, you always can remove or rename fields to show in a custom report type from "Fields Available for Reports" section.

Next, create new report using report type above to find out which reports are created using particular report type.



Sunday, October 13, 2013

Cannot send email from Salesforce Sandbox

If you just create new sandbox or refresh a sandbox Sandbox, you will not able to send email: manually, from workflow or from apex code. This is because since Spring '13 release, Salesforce has change email deliverability to System email only.

You can change the email deliverability to All email from Setup > Email Administration > Deliverability.










If system administrator have not change email deliverability, user will not see Send an Email button in Contact, Lead or Case related list, although it is has added to the object related list page layout.

From Workflow or Auto-Response Rules, email will not send out and there is no notification.
From apex code, you will found this error "Email Privileges Revoked", see this blog.

You can check Email Logs to audit all email send from and to Salesforce, email logs accessible from Setup > Logs > Email Log Files.

Friday, October 4, 2013

Salesforce: Default Fields in report

When create a new report in Salesforce, Salesforce will automatically put some fields into new report. We cannot customize the default fields when report created.

However, for custom report type, system administrator able to customize it. Here we go:

1. Create New Report Type
  • Setup - Create - Report Types
  • Select Primary Object, enter Label, Description, Category and select Deployment status
  • If you need to relate to other object, select from "click to relate another object"
  • Save



2. Edit Fields for Reports
From "Fields Available for Reports" section, click "Edit Layout" button.
  • Drag and drop fields from available fields (in right panel) to left layout to add field to be available in report builder, or drag and drop fields from page layout to right panel to remove it.
  • You can add lookup field by click link "Add fields related via lookup »", example: you are in Opportunity object, and want to add Account Address field
  • You can "Create New Section" in page layout, section created will be shown in different tree in the report builder
  • Click Edit Properties button to make the field show by default when user create new report in report builder, but before that you have to select fields (you can select multiple fields by hold Ctrl button). A window will be popup and you may change the field name will be Display As other label in report builder.
  • You can drag and drop section row up and down (if you have more than 1 section), this will effect to field tree position in report builder.
  • Save


Compare to the screenshot below for the layout in report builder:

Read here for more information.

Wednesday, October 2, 2013

Salesforce: Permission to edit User Quota

Background: Super user need to enter all Sales Rep quota for every quarter. As system admin, we can enter it manually in user detail page (if not too many sales rep), or using Data Loader if you have a lot of users need to update (see this blog). But, would it be nice if Sales Ops (read: Super User) able to manage Sales Rep quota by themselves?

Here is the solution, use Delegated Administration
Go to Setup - Security Controls - Delegated Administration
Create New button and enter a name for delegated group.

You can leave option to Login Access disable for security concern.
From here, select user allowed to update quota in Delegated Administrators
Then enter Sales Rep role in to be managed in User Administration
Done - you can left Assignable Profiles and Custom Object Administration as they are not used for this scenario.

To note, enabling delegated administration will give user ability to:
  • Creating and editing users and resetting passwords for users in specified roles and all subordinate roles, including setting quotas, creating default opportunity teams, and creating personal groups for those users. But, if you not add any Assignable Profiles, user cannot select any profile, and since profile is a mandatory field in user creation, user actually cannot create user, got it?
  • Unlocking users
  • Assigning users to specified profiles, this is again depend on Assignable Profiles given.
  • Logging in as a user who has granted login access to their administrator, this is depend if  Login Access enable for particular delegated group.
  • Managing custom objects created by an administrator, depend on object given in Custom Object Administration.

For more information, read this doc.



Tuesday, October 1, 2013

Salesforce: Convert Lead with Campaign Influence & Primary Campaign Source


In this blog, we are going to discuss Lead conversion and its relationship to Campaign and Opportunity.

Here is the scenario:
1. Create a new Lead

2. From Campaign History in Lead Related List, add "GC Campaign", then add "DM Campaign" with both Status = Sent.

3. Edit "GC Campaign" Status to Responded

4. Convert Lead: create new Account, Contact, and Opportunity

5. In Campaign, Lead automatically changed to Contact for both Campaign Members related list.

6. In Account, Contact added in Contacts related list, Opportunity added in Opportunities related list.

7. In Contact, both campaigns were added to the Campaign History related list, with Status and Responded brought over from Lead.

8. In Opportunity, the campaign is added as Campaign Influence related list with Contact Name, Primary Campaign Source = DM Campaign; this is because "DM Campaign" is the latest campaign attached to the Lead, although the Status is not Responded.

9. In the "DM Campaign", the Opportunity created is added in the "Influenced Opportunities" related list.

10. If the user changes the Primary Campaign Source in the Opportunity page layout from DM Campaign to GC Campaign, Opportunities in the Campaign related list move to GC Campaign as well.


Campaign Influence
System Administrators can configure Campaign Influence from Setup - Customize - Campaigns - Campaign Influence, such that only Campaigns within the last 120 days (see Specify Campaign Influence Time Frame) with the rule Responded = True will be associated with Opportunities as Campaign Influence.


Primary Campaign Source
Primary Campaign Source in Opportunity automatically refers to the last associated campaign on a lead before lead conversion, or the last associated campaign on a contact (if the contact was manually added to SFDC without being converted from a lead). See the Member First Associated field in the Campaign History related list in Contact or Lead.

screenshot from Contact / Lead

Opportunity may be influenced by more than one campaign. If you enable Campaign Influence and the campaign fits into Time Frame and Rules, when you convert a Lead, all Campaigns related to the Lead will be created as Campaign Influences in the Opportunity related list.

You can also manually associate additional influential campaigns with an opportunity, but only one will be marked as the Primary Campaign Source. A campaign manually added to an Opportunity will not be added back into the Opportunity related list in Campaign. You can view influential campaigns from the Campaign Influence related list on the Opportunity detail page.

Screenshot from Opportunity

Primary Campaign Source field on the Opportunity detail page designates the most influential campaign for that opportunity based on the data in the Campaign Influence related list.


Reference: What is Campaign Influence?


Page-level ad