Pages

Showing posts with label Formula Field. Show all posts
Showing posts with label Formula Field. Show all posts

Monday, December 12, 2022

Salesforce: Using Formula Field

The formula field is one of the best features of the Salesforce platform for admin (and developer). Despite the limitation and restrictions, it still serves a lot of benefits. 

Some restrictions:

  • You can’t use long text area, encrypted, or description fields in formulas.
  • The value of a field can’t depend on another formula that references it.
  • You can’t delete fields referenced in formulas. Remove the field from the formula before deleting it.


But, where the formula field can and cannot be used?

Page Layout - Yes, including dynamic form, search layout, and compact layout. But the formula field is not searchable.

Report - Yes, including use as a filter

List View - Yes, including use as a filter

Validation Rule - Yes, except that you can't set the error message location at a formula field

Approval Process - Yes

Sharing Rule - No, the criteria based sharing rule does not support by formula field, you can vote on the idea here, here, and here; here is the original idea but has been marked as partially delivered although the item delivered has nothing to do with sharing rule.

Email Template - Yes

Flow - Yes

SOQL - Yes


If there are other places we can or cannot use formula fields, feels free to comment below this blog. 


Reference:

Friday, March 12, 2021

Adding Image to Salesforce

Adding Image to the Lightning page

This is actually pretty simple:

  • add a Rich Text component in Lightning App Builder
  • copy the image from a browser
  • paste into the Rich Text component 
Bonus point, since this is a component, you can make use of "Set Component Visibility" to show/hide the Rich Text component based on the record field value or device or user detail or permission. Also, can use filter logic to show/hide the component.

In the rich text component, you can combine this formatted text and additional images.



Adding Image to Page Layout

Salesforce does not have a field with the type = image, however, we can make use formula field return text with the Image() formula. 

IMAGE(image URL, alternate text [, height, width])

You can enter any URL into the image URL, such as: 
IMAGE("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf8aRfxLWfr0CQLooZltAZkJjucrOLoA13nE_-TGqy3Pwlf8yaXOV_zMubAY2XJv1qTmkX0-tnqAvr0za3Op2g3XQ4SF-ZNtW4NoRyFCB6rGzlXmbJaFM9QRS2RAt2PQUhU526dUn-d-E/w400-h100/sc+utf8.png", "Hello", 157, 627)



or simply populate the Image URL and alternate text for the parameter
IMAGE("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf8aRfxLWfr0CQLooZltAZkJjucrOLoA13nE_-TGqy3Pwlf8yaXOV_zMubAY2XJv1qTmkX0-tnqAvr0za3Op2g3XQ4SF-ZNtW4NoRyFCB6rGzlXmbJaFM9QRS2RAt2PQUhU526dUn-d-E/w400-h100/sc+utf8.png","Hello")



However, the above image is public or depends on external storage. We can make use of the Salesforce library to store the images, check out this article. 


Static Resources
Another option is to load the image as Static Resources.

IMAGE("/resource/This_is_image", "Hello")



Since this is a formula field, you can make use of IF() function to determine which image to show based on the criteria.


FREE Images Components 📷 by SharinPix

FREE Images Components 📷 by SharinPix is a native Salesforce picture management based on Salesforce images capabilities. Use the components to display images on a record page. Choose from a banner format, photo album, slideshow or a slider. You can even upload images from the components as well!

Check out this component from AppExchange, or the paid version Image/Photo Management for Salesforce for more features.




Monday, September 9, 2019

Salesforce: Query Multi-Currency Field

When you have multi-currency enabled in your Salesforce org., you will see the converted value of currency fields in the page layout, list view, and report.

Creating Record

When creating a new record, the default selected currency is User currency, instead of Corporate currency.

Viewing Record

  • If User currency equal to record currency --> no amount conversion 
  • If User currency different from record currency --> record currency appear at front, continue with user current and the conversion amount under brackets. This has nothing related to corporate currency.


Page Layout

My user currency is USD and the corporate currency is USD too.



If I change my currency to SGD


List View

The same goes for ListView, if the record currency is different from your user currency, the list view will show the amount in the opportunity currency and the value in your currency in brackets.


Report

Currency fields in reports are shown in their original currencies. Salesforce gives the option to get the values in the Opportunity record currency and in the converted amount -- by default, when creating a report, the converted currency will be in the user personal currency, but the user will be able to change to any active currency.


SOQL

When you query Salesforce currency fields, SOQL will always return currency values as defined in the CurrencyIsoCode.


Format() and convertCurrency()

We can use Format() and convertCurrency() functions for currency field in SOQL:
- Use FORMAT with the SELECT clause to apply localized formatting to standard and custom number, date, time, and currency fields, the format applied these fields reflect the appropriate format for the given user locale.
- Use convertCurrency() in the SELECT clause to convert currency fields to the user’s currency.

Looks at this sample: SELECT Id, CurrencyIsoCode, Amount, convertCurrency(Amount) UserAmount, FORMAT(amount) TextAmount, FORMAT(convertCurrency(amount)) convertedCurrency FROM Opportunity order by currencyisoCode



You can’t use the convertCurrency() function in a WHERE clause. If you do, an error is returned, but you can use the following syntax to convert a numeric value to the user’s currency from any active currency in your org. WHERE Object_name Operator ISO_CODEvalue

e.g. SELECT Id, Name FROM Opportunity WHERE Amount > USD5000
In this example, opportunity records are returned if the record’s currency Amount value is greater than the equivalent of USD5000. For example, an opportunity with an amount of USD5001 is returned, but not JPY7000.

How to get currency value in corporate currency using SOQL?
In Spring ’18 release, Salesforce introduces new formula functions ADDMONTHS, CURRENCYRATE, MCEILING, MFLOOR and WEEKDAY. So this purpose, we can make use of CurrencyRate() function.

CURRENCYRATE returns the conversion rate to the corporate currency for the given currency ISO code. If the currency is invalid, returns 1.0.

We can create a simple formula field
Amount / CURRENCYRATE(TEXT(CurrencyIsoCode))

Here is the result:


If you implement dated exchange rate, CurrencyRate() function do not support it yet, it will always use the standard exchange rate, unless you always keep the conversion rate aligned.


Reference:


Sunday, December 25, 2016

Salesforce: Tips on Cross-Object Formulas


Cross-object formulas are formulas that span two related objects and reference merge fields on those objects. Cross-object formulas can reference merge fields from a master (“parent”) object if an object is on the detail side of a master-detail relationship. Cross-object formulas also work with lookup relationships.

To create a cross-object formula when building a formula, enter the relationship names of the objects to which you are spanning followed by the field you want to reference. Separate the relationship names of each object and the field with periods.

For example, enter Contact.Account.Name to reference the Account Name for a contact associated with a case in a formula field on the Case object. Be sure to use the relationship names of the objects, not the labels. Although the relationship name is often the same as the object name, it is technically the field name of the relationship field.

To reference the parent account name from Account object, the syntax is Parent.Name, not Account.Name. When referencing a custom object, add two underscores and the letter r to its name. For example, Position__r.title__c references the Job Title field (title__c) on a Position custom object.

You can reference fields from objects that are up to 10 relationships away. Cross-object formulas are available anywhere formulas are used except when creating default values.

If you create a formula that references a field on another object, users can see the field on the object even if they don’t have access to that object record. For example, if you create a formula field on the Case object that references an account field, users can see this field even if they don’t have access to the account record.

Tips
Formula fields can expose data that user do not have access, such as:
- user do not have access to the field level security within the same object
- cross-object where user do not have access to the record
- cross-object where user do not have access to the record and the field
- cross-object where user do not have permission to the object


Roll-Up Summary Field
If a roll-up summary field doesn’t contain cross-object field references or functions that derive values on the fly, such as NOW or TODAY, it can calculate the values of formula fields.






Reference:



Wednesday, August 17, 2016

Salesforce: Working with Minute, Hour, Day in Workflow, Validation Rule and Formula Field


Use Case: based on some criteria, Event Reminder must be set to 30 minutes prior Event Start date time.

Solution:
Use Workflow with Field Update or Process Builder, but the logic should be the same. In this case, I'll use Workflow with Field Update for simplicity.

1. Create Workflow Rule and determine the business logic when Field Update action should trigger.

2. Create Field Update action with following formula: ActivityDateTime - 0.020833

Desc:
- ActivityDateTime = Event Start
- 0.020833 come from 0.5 / 24, where 0.5 = 30 minutes

Notes: when we use a number in Workflow or Formula or Validation Rule for Date or Date/Time field, it is for 1 day count. So for 2 hours, it would be 2/24 = 0.083333

So, when you try to calculate fields of date (date/time), example: NOW() - CreatedDate, this will produce number in days, example: 32.50 meaning 32 days 12 hours.


Reference: Date/Time Calculations in Formula Fields, Workflow Field Updates and Validation Rules



Friday, June 24, 2016

Salesforce: Show value only to Owner and Manager


Use case:
A scoring system has been implemented to auto calculate if a lead is valid to pursue. But, the score should only visible to the record owner manager.

In Salesforce, we only can set field visibility using Field Level Security (FLS) which is based on Profile. But record owner manager have the same profile with the record owner, and the manager may owned a lead which he supposed not able to see the score, only the manager's manager able to see it.

Solution:
1. Set the score field not visible from all Profile with FLS
2. Create a formula field and make it visible to all Profile
IF( $User.Id = Owner.ManagerId, Score__c, null)

For other scenario, if only the owner and owner's manager should be able to see the score, use this formula:
IF( $User.Id = OwnerId || $User.Id = Owner.ManagerId, Score__c, null)



Tuesday, July 7, 2015

Salesforce: Functions versus Rules matrix

As Salesforce admin, function is one of my favourite feature, you can use it in:
  • Approval Entry Criteria
  • Approval Step
  • Assignment Rule
  • Auto-Response Rule
  • Custom Button and Link
  • Escalation Rule
  • Field Update
  • Formula Field
  • Validation Rule
  • Workflow Rule

As of Summer'15 release, there are more than 60 functions available, not to ask if you have use all of them, but do you aware if they are exist? I never know and use EXP, LN, LINKTO, SQRT and a few more, and hardly use ABS, BR, DISTANCE.

Do you also know, some of the function only available in certain area, such as:
  • HYPERLINK, IMAGE only in Formula Field
  • VLOOKUP only in Validation Rule
  • FORMAT_ADDRESS, GETRECORDIDS, and a few more only in Custom Button/Link

I try to summarize functions available in each area:


Click here to download the Excel file. Let me know if I missed any or wrong information shared.


Tuesday, September 30, 2014

Salesforce: How to sort Multi-Select Picklist in View ?

Multi-Select Picklist is a great feature for user to select multiple values controlled. You can use the multi-picklist field in View, Report, etc.

Recently we have issue when used it in View, user not able to sort b value using this multi-select picklist field. A quick idea is to create a text formula field, but looking at multi-select picklist fields can only be used in these functions: INCLUDES(), ISBLANK(), ISNULL() for formula field, TEXT() is out of picture here.

ISCHANGED() and PRIORVALUE() only in assignment rules, validation rules, workflow field updates, and workflow rules in which the evaluation criteria is set to Evaluate the rule when a record is: created, and every time it’s edited.

Solution:
Create text formula field with INCLUDES()
Example:
 IF( INCLUDES( Country__c, 'Singapore'), 'Singapore',  
     IF( INCLUDES( Country__c, 'Australia'), 'Australia',  
         IF( INCLUDES( Country__c, 'Malaysia'), 'Malaysia',  
             IF( INCLUDES( Country__c, 'Thailand'), 'Thailand',  
                 IF( INCLUDES( Country__c, 'Hong Kong'), 'Hong Kong', 'Other')  
             )  
         )  
     )   
 )   

Cons: when you have multiple values in the field, it will return based on the first value match.


Reference: Tips for Working with Picklist and Multi-Select Picklist Formula Field



Thursday, February 20, 2014

Salesforce: Formula with CONTAINS() function

You can use CONTAINS() function in Salesforce from formula field, validation rule, workflow rule and etc. But it commonly used in validation and workflow rules to search for a character or string in a text field.

If you are reading Salesforce documentation, it said the functions is to compare two arguments of text and returns TRUE if the first argument contains the second argument. If not, returns FALSE. Be aware that comparison using Contains() is case sensitive.

This function is only for Text field. For Picklist, add TEXT() function to convert the picklist value to text. For Picklist (Multi-Select), use INCLUDES() to see if a multi-select picklist has a specific value.

Usage: CONTAINS(text, compare_text)
CONTAINS will return TRUE if "compare_text" is found in "text" and FALSE if not.

 CONTAINS("abc", "abcd") --> FALSE  
 CONTAINS("abcd", "abc") --> TRUE  

Example: IF(CONTAINS(Product_Type__c, "part"), "Parts", "Service")
In this example, we compare if part is exist in a custom field Product_Type__c

Some Use Case:
1. Searching for Text
Example: CONTAINS(Comments__c, "BadWord")
Returns TRUE if "BadWord" is found anywhere in Comments__c

2. Check if an unknown string or character matches a defined set of strings or characters.
Example: CONTAINS("0123456789", Address)
Return TRUE if Address values such as 1, 2, 9, 01, 789, or any other substring of "0123456789"

Example: CONTAINS("CA:NV:FL:NY", BillingState)
Return TRUE if BillingState is CA or NV or V:F or L or FL:NY or any exact match of "CA:NV:FL:NY".
NOTE: when using contains with the multiple operator (:) contains then becomes equals.

You can enhance above formula to be
AND(LEN(BillingState)=2,CONTAINS("CA:NV:FL:NY",BillingState))
this formula will ensure that BillingState is 2 characters in length. But, it still return TRUE for :N or V: and other any 2 character EXACT match of each state "CA:NV:FL:NY"

Of course you can still enhance the formula above to check if the 2 characters do not contain :

For a picklist field, use TEXT(picklist_field_name) to convert a picklist value into a text value so that you can work with the value in functions that support text value.



Reference:


Friday, February 7, 2014

Salesforce: Formula for Owner

In Summer '13 release, Salesforce open Owner lookup field and made it available for cross-object formula. Owner field is special compare to other fields, because if the object is available for Queue (e.g. Case, Lead, and custom object), it can be linked to User object or to Group object (owner is a Queue).

You can access things like the record owner email address or owner manager name through formula field or workflow rule.

For example, if you need to get owner email address and it is not for queue, your formula would be Owner:User.Email, this formula field will return blank, if the object is available for Queue and record owned by a Queue.

From above sample, if the object supported by Queue, you can enhance the formula to:
IF( ISBLANK(Owner:User.Id), Owner:Queue.QueueEmail, Owner:User.Email )

To get User name or Queue name:
IF( ISBLANK(Owner:User.Id), Owner:Queue.Name, Owner:User.FirstName & " " & Owner:User.LastName )

User and Queue objects can be referenced on the Owner lookup, but must be explicitly selected, see screenshot below:






Tuesday, February 4, 2014

Salesforce: Simple Trigger to Act as Workflow with Field Update

In previous blog, I discuss about how to write a simple trigger to act as validation rule. In this blog, I'll continue to use trigger to act as workflow with field update.

Scenario: it is good that we manage user only able to enter Singapore or SG, so no more SGP or Spore for the Billing Country. But, even we have only Singapore and SG, it would be best we only have SG, this will make the report even easier and better.

We can enhance existing trigger and add few lines. I'll not write about custom object and how to start write trigger. Here you go:


You can right click the image above and select 'Open image in new tab' if you are using Google Chrome to get better image resolution or get the text version from this URL.

Let me give a quick explanation line added in the code:
  • Line 3, add new list for Account object, will use it to update Account.
  • Line 20 & 21 and 39 & 40, assign Country Code from reference table into Billing Country. You may ask why we need line 39 & 40 since user already enter 2 characters only, and it match to the Country Code. Because without that 2 lines, trigger will not update Account with Country Code from reference table, so when user enter sg or Sg, system will accept it, this is not so tidy as we want all be SG, get it? 
  • Line 54 - 56 to update Account before insert or before update.


Sunday, January 26, 2014

Salesforce: Default Lead Conversion

In previous blog, we discuss about validation rule when user convert lead. Now, we have new requirement, can we set default values when user click Convert button in Lead?

By default there is no function  from Salesforce to set the default value, but there is a workaround for this, which is adding parameters to the URL. Here we go:

1. Create custom Convert button
Use this button instead of standard Convert button.
  • Go to Setup - Customize - Leads - Buttons, Links, and Actions. 
  • Click New Button or Link
  • You can select Content Source = OnClick JavaScript

  • or Content Source = URL

  • Example: if you want default "Do not create a new opportunity upon conversion" is checked, add this formula in the formula field:
    • JavaScript: window.location.href="/lead/leadconvert.jsp?retURL={!Lead.Id}&id={!Lead.Id}&nooppti=1"
    • URL: /lead/leadconvert.jsp?retURL={!Lead.Id}&id={!Lead.Id}&nooppti=1

2. Edit Lead Page Layout
Remove standard Convert button and add new custom button created in Lead page layout, you can the button name  different.
  • Go to Setup - Customize - Leads - Page Layouts
  • Click Edit link for page layouts
  • Select Buttons in the layout
  • Drag and drop the button to add and remove 


Here list of parameters you can use in the custom button:
Convert Lead
  • "Do not create a new opportunity upon conversion" checked -- nooppti=1
  • "Send Email to Owner" checked -- sem=1
  • "Opportunity Name" -- noopptt={!Lead.Name} - opty
  • "Converted Status" -- cstatus=New Status
Task Information
  • "Subject" -- tsk5_fu=Mission Critical Task
  • "Status" -- tsk12_fu=Deferred
  • "Priority" -- tsk13_fu=High
Description Information
  • "Send Notification Email" -- email_followup=0
  • "Comments" -- tsk6_fu=No Comment
Reminder 
  • "Reminder" -- IsReminderSet_fu=0

You can check more fields you can pre-populate by default or if you have custom Task field to add, go to View Source by right click the page and look for name related to the field, example: <input  id="00N50000002DnFJ_fu" maxlength="200" name="00N50000002DnFJ_fu" size="20" type="text" /> For this example, the parameter would be 00N50000002DnFJ_fu=abc

Hope this help Salesforce admin.


Friday, January 24, 2014

Salesforce: Phone call from Smartphone

This blog is not related to Salesforce1 platform or mobile app promoted in Dreamforce '14. But, we have a use case, when user would like to call a number using smart phone or tablet when browsing from Salesforce.com website.

Here is the scenario, sales rep would like to call a Contact in Salesforce. Rather than to remember or copy the number to a paper, can the sales rep call directly from Salesforce webpage since he use his smart phone to browse Salesforce?

Phone field in Salesforce is not click-able, so by default, there is no way to call from Salesforce website. But, we have the workaround to use a formula field.

So, here we go:
  • Example to use standard Phone field in Contact object 
  • Create a formula field with return type = Text
  • Use this formula = HYPERLINK("Tel:" & Phone, Phone )
  • Add the formula field to Contact page layout, you may remove the default Phone field from page layout to avoid confusion
User will see this new field in page layout and it is click-able. Screenshot below taken from when user click the Phone formula field.




Sunday, January 19, 2014

Mass deactivate Salesforce Validation Rule or Workflow Rule

As of now Winter '14 release, Salesforce do not have switch to mass turn OFF and ON Validation rules and Workflow rules. In some use case, we need to turn it off, such as in event of mass load data.

But, using some trick, we can make use of Custom Setting as a master switch. Custom Setting is mostly used by developer and not famous among Salesforce admin. I blog about custom setting sometime last year, read here.

Here is the step, let say we want to deactivate all Validation rule in Account:

1. Create Custom Setting
  • Setup - Develop - Custom Settings
  • Click 'New' button
  • Enter Label 'Master Validation', Object Name, Description and select Setting Type = Hierarchy
  • Save


2. Create Fields in Custom Settings 
  • Continue from step 1 above, in custom setting created 
  • Click 'New' button in Custom Fields related list
  • Select Checkbox field type
  • Enter field name and label 'Account Active'
  • Enter Description and Help Text as necessary, Default Value does not really mattered.
So, this is what we have now after add field.


3. Manage Custom Settings 
  • Click Manage button for that Custom Setting to set Default Organization Level Value
  • You should see all fields available 
  • Click Edit button and make sure 'Account Active' is checked
  • Save


4. Field Value for User or Profile (Optional)
You also can determine each user Profile value, users or profiles not added here will use Default Organization Level Value set in step 3 above.
  • Click New in Manage Custom Setting 
  • Select user or profile in the lookup window
  • Check active checkbox button
  • Tips: if you just need to deactivate validation rule only to a profile, example: only for System Administrator when he load data using Data Loader, you just need to add 1 profile here to deactivate the value and let the rest of profiles Active via Default Organization Level Value.


5. Modify Validation Rule
Add following formula '$Setup.Master_Validation__c.Account_Active__c' in Error Condition Formula.

6. Done


Summary:
  • Pro: Admin have full control to ON or OFF validation rule and workflow rule based on Object and Profile (or even User)
  • Cons: Each existing validation rule and workflow rule need to modify and add additional formula into the formula.

Saturday, December 28, 2013

Salesforce: Lead Conversion Validation Rule

We blog on lead field conversion mapping sometimes back this year. In this blog, we would like to discuss how to run Validation Rules on Lead conversion process, this mean to block Lead conversion if not satisfy any rules. Few items to check:

1. Require Validation for Converted Leads
Earlier this option is called as Enforce Validation and Triggers from Lead Convert. Make sure this setting is enabled, otherwise Validation Rule on Lead conversion will be ignored. Go to Setup - Customize - Leads - Settings, enable Require Validation for Converted Leads. If you do not see this option, log a case with Salesforce support to get this option enable for you.

When this checkbox selected, it will check all validation rules in related objects of Lead conversion, including: Lead, Account, Contact and Opportunity (if Do not create a new opportunity upon conversion is not checked).



2. Set Validation Rule in Lead object
Use Case: company would like to stop lead conversion when Title is blank.
Here we go:
  • Create a validation rule in Lead using formula IsConverted
  • Make sure the rule is Active, many people forget to activate it and spend a lot of times before realize it is not active.


3. Set Validation Rule in target object
Target object here is Account, Contact and Opportunity. 
Use Case: company would like to block Account without website.
Although it is possible to create the rule in Lead, but if the validation rule in Account level, even you skip it in Lead object validation rule, validation rule in Account will take care for this.


Note:
When you have validation rule in both target, example: Account and Lead object with checking IsConverted, Account validation rule will kick-in before Lead validation rule with checking IsConverted field. This make sense because Salesforce will create / update Account before update Lead with IsConverted = True.


Reference:


Thursday, December 12, 2013

Salesforce: Close Case in one click

To close a Case in Salesforce, user need to have Edit permission on Case object. By default, when a user click Close Case button, user will be bring into a new page to enter information needed before close the case. Admin can set mandatory fields at the Close Case page, from Setup - Customize - Case - Page Layout and look for Case Close Page Layouts.

But, can we make this simple? Meaning just click a button to close an open case without have to open a new page. Yes, by using custom button. Here we go:
  1. Setup - Customize - Cases - Buttons, Links, and Actions
  2. Click New Button or Link, enter Label and Name, select Detail Page Button in Display Type and Behavior select Execute JavaScript
  3. Paste JavaScript script below
  4. Add custom button created to the page layout and remove default Close Case button, you can have multiple page layout with different button based on user profile and Case record type.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
if ({!NOT(Case.IsClosed)}){
   caseObj.Status = 'Closed';
   var result = sforce.connection.update([caseObj]);
   if (result[0].success=='false') {
      alert(result[0].errors.message);
   } else {
      location.reload(true);
   }
}

Another option is to enable Closed value available in Case Status. By default, this value will be not available when user Create or Edit the Case, but we can enable it. Here we go: Setup - Customize - Cases - Support Settings, enable Show Closed Statuses in Case Status Field. This will make Closed status available when user create or edit Case, user also will not bring into Case Close page any more.

In the same Case Support Setting page, admin also can hide Save & Close button by enable Hide Save & Close Button and Cls Links.


How about if I want to limit only certain profiles can close case?
Easy... create validation rule with this formula, sample:
RecordType.Name = 'CSD Case' && ISCHANGED(IsClosed) 


Read this document for more information on Closing Cases.


Friday, November 22, 2013

Salesforce: Lead Conversion Field Mapping

When you convert a Lead, standard Lead fields automatically converted into Account, Contact, and Opportunity - as mapping below:
Lead FieldMaps to
AddressAccount: Billing Address
Contact: Mailing Address
Annual RevenueAccount: Annual Revenue
CampaignOpportunity: Primary Campaign Source
If the lead has multiple associated campaigns, the most recently associated campaign is inserted into the opportunity regardless of whether the user has sharing access to it.
CompanyAccount: Account Name
Contact: Account
Opportunity: Account Name
Opportunity: Opportunity Name
Company Name (Local)Account: Account Name (Local)
DescriptionContact: Description
Do Not CallContact: Do Not Call
This field is not updated for leads converted to existing contacts.
EmailContact: Email
Email Opt OutContact: Email Opt Out
This field is not updated for leads converted to existing contacts.
FaxAccount: Fax
Contact: Fax
Fax Opt OutContact: Fax Opt Out
First NameContact: First Name
First Name (Local)Contact: First Name (Local)
IndustryAccount: Industry
Last NameContact: Last Name
Last Name (Local)Contact: Last Name (Local)
Lead OwnerAccount: Owner
Contact: Owner
Opportunity: Owner
Lead SourceAccount: Lead Source
Contact: Lead Source
Opportunity: Lead Source
Person Account: Lead Source
MobileContact: Mobile
No. of EmployeesAccount: Employees
Partner AccountOpportunity: Partner Account
This field is not updated for leads converted to existing opportunities.
PhoneAccount: Phone
Contact: Phone
RatingAccount: Rating
TitleContact: Title
WebsiteAccount: Website

As you see from above mapping, Lead Source is only mapped to Contact and Opportunity, not to Account Source, but if you need it, here is the workaround by using custom Account Source field - Map Lead Source field on Lead object to Account Source field on Account object during lead conversion. If you aware the default Account Source picklist values are sync with Lead Source, so you may need to make sure this custom Account Source picklist values need to manually sync. At some points, Lead Source to Account Source mapping has been automated by Salesforce.

If you are not using custom fiscal years, the Close Date of the opportunity created is automatically set to the last day of the current fiscal quarter.

If you are using custom fiscal years, the Close Date is the last day of the current fiscal period. If you are using custom fiscal years and a fiscal year has not been defined for the current date, the Close Date is the end of the current calendar quarter.

Custom lead fields only can be converted into custom account, contact, and opportunity fields as specified by the system administrator (not map to the standard field). To specify the mapping for custom lead fields:
  1. From Setup, click Customize | Leads | Fields | Map Lead Fields.
  2. For each custom lead field, choose a custom account, contact, or opportunity field into which you want the information inserted when you convert a lead.
  3. Click Save.
It's best practice to map custom lead fields to other custom fields with the same field type, but here some exceptions and tightened:
  • You can only map Number to Number, Currency to Currency, and Percent to Percent field with the exact same field length and same decimal point.
  • The lookup field only can be mapped to other lookup fields with the same lookup object.
  • You can map from Text and Text Area to Picklist, even the text value does not exist in picklist value.
  • You can map from Picklist to Text, Text Area, and Long Text Area, but if the picklist value is longer than the length of the text field, it will throw system error upon conversion process - System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG
  • You can map from Auto Number, Text and Text Area to Text, Text Area, and Long Text Area field.
  • You can map from a Formula field in lead, it treats as a normal field depends on the formula return type.
  • You cannot map a Formula field into account, contact, and opportunity.
  • Standard lead picklist fields that are blank are mapped to the default picklist values for the account, contact, and opportunity (remember to check default value if you are using Record Type for the target object).

Monday, November 11, 2013

Salesforce Custom Setting

Although Custom Setting is similar with Custom Object, but they are very different and totally for different usage. Custom object used to store all data within Salesforce for any transactions, it works similar with standard object, such as: Account, Contact, Opportunity, etc and you can create custom tab for that object.

While Custom Setting used to store application configurations, such as: value based on each application type or user. You cannot put show custom setting value directly as a custom tab. But, to access custom setting data, you need to access it from: Formula fields, Validation rules, Workflow rules, Apex class, and API.

There are 2 type of custom setting: List and Hierarchy. Formula field, Validation rule and Workflow rule only can access Hierarchy type custom setting, while Apex and API can access both. Once you select the type, you will not able to change it.

If the custom setting is a list, you can add set of data. For example, if your application had a setting for country codes, each set might include the country's name and dialing code.

If the custom setting is a hierarchy, you can add data for the user, profile, or organization level. For example, you may want different values to display depending on whether a specific user login to system, or a specific profile, or for general users.

To access hierarchy Custom Setting from formula field, workflow rule or validation rule:
{!$Setup.CustomSettingName__c.CustomFieldName__c}

Use case: all users have to select Account Active status, except System Administrator.

Here is the step to use Custom Setting in Validation Rule:
1. Create Custom Setting:  Setup | Develop | Custom Settings
2. Create Fields in Custom Settings

3. Manage Custom Settings
Enter Default Organization Level Value, you can skip the value for User or Profile level.

4. Modify Validation Rule
($User.ProfileId <> $Setup.Rules_Id__c.Exception_Id__c) && ISBLANK(TEXT(Active__c))

Checkout this blog for step-by-step to configure Custom Setting.


To access Custom Setting from API:
SELECT Id, Name, Exception_Id__c, Name__c FROM Rules_Id__c
This is very similar with SOQL query to custom object, isn't it?


Limitation of Custom Setting:
  • Maximum total data of 10 MB, but if you have less than 10 license users, multiply 1 MB with number of users
  • 300 fields per custom setting.
  • Can’t share a custom setting record.
  • No owner assigned for each custom setting record
  • Each custom setting counts against the total number of custom objects available for your organization.

You can access Custom Setting field through SOAP API, run SOQL to get the values, and it can be deployed using Change Set.

To deploy custom setting data/value, you can use Data Loader, see this blog.


Reference:



Page-level ad