Pages

Wednesday, December 9, 2015

Salesforce: State and Country Picklists

By default, State and Country is textbox field, where user can enter any data. Some organization hire developer to write trigger to validate the data entered is valid. Another option is to use AppExchange product such as AddressTools Premium or AddressTools Free.

But if you are not aware, Salesforce actually have something called State and Country Picklists, this is out of the box feature to change textbox field to picklist for both State and Country, this is applicable for shipping, billing, mailing, and “other” address fields in standard object:
  • account
  • campaign members
  • contact 
  • contract
  • lead
  • person accounts
  • quotes
  • service contracts 

Benefit
When State and Country Picklists is activated, users will be not able manually to type into State and Country, but they have to select from picklist. This will make your data clean, e.g. United States maybe enter as USA, U.S., United States America, this will make you will be difficult to analyze data correctly.


How to activate this?
1. Navigate to Setup | Data Management | State and Country Picklists

2. Click Configure states and countries in step 1
  • You can set default country, in case your business mostly only happened within a country. 
  • By default Salesforce will provide 239 countries and some of them have States/Provinces. For countries that you know should have State, but not available, click Edit link on that country, click New State button to add State. This manual process will take a lot of time when you need to enter many State not available out of the box.
  • You also can modify the Country Name and Integration Name. Integration Name must be unique, Salesforce uses this value to integrate new picklist values with former text-only values. It is not case sensitive. When you add new country, Country Code must be unique and you cannot modify standard country code.
  • To hide a country visible for user to select in picklist, unselect Visible checkbox

3. Click Scan Now in step 2
  • You will receive 2 emails: one regarding affected address data and one regarding affected customizations. 
  • For customizations scan result, you need to download a text file from document, this will include where State and Country used in your org: 
    • Apex Class
    • Visualforce Page
    • Apex Trigger
    • Assignment Rule
    • Auto-Response Rule
    • Email Template
    • Escalation Rule
    • Field Set
    • List View
    • Report
    • Validation Rule
    • Custom Button or Link
    • Workflow Rule
    • Matching Rule
For reports and list views, it will not include reports and list views in personal folder or visible only to a user, except it owned by user who run the scanner.
4. After get two emails above, click Convert Now in step 3
For address (state and country), you need to select the data and select a value from Change To picklist, If you do not know the right value at that moment, you can map it to "Unknown value". Users user open the record, they will see original state and country (not Unknown value), but they will encounter error to save, unless they change the state or country to a valid value before saving. You should only map to "Unknown value" when you do not know the correct value.
This step will take a lot of time to clean up invalid data manually.

5. Once conversion process finish, you will be able to click Enable button at step 4 Turn on state and country picklists.

Notes:
1. If you change a country name at step 1, the original name will be shown in Change To picklist when you convert state or country to picklist, just select the original name, and it will use value renamed, example: Viet Nam to Vietnam. This maybe a Salesforce defect, but not a blocker.



2. Notice two new fields created for all objects with standard address field, which is BillingCountryCode and BillingStateCode.

Before enable state and country picklist:

After enable state and country picklist:



3. From the last screenshot above taken from SOQL query, invalid value converted to 'Unknown value' will not have value in the Code field. For valid values, code will be auto populated with the Country Code and State Code.

4. When we run report, we can see the old value with suffix (text only)



5. When you open existing report with state or country, it will prompt you to update the report with new picklist field.

But, if you do not have permission to edit the report, here is the screenshot.

Effect with Insert / Update (integration or mass loader)
  • So which field should I use? BillingCountry or BillingCountryCode or both? You can provide only one value, either name or code, and the other value will be auto populated by the system. But if you populate both for some reason, make sure the code is align with the country name, otherwise the insert/update process will be failed. The same goes for State.
  • The country / state name or code must be exist in the picklist value defined, otherwise the insert/update process will be failed. 
  • When you insert / update State, make sure that state is available for that particular country, otherwise the process will failed.

So this is how it looks like when you had State and Country Picklists enabled. Notice both Country and State is a picklist, and State picklist value is depend on Country selected.



Reference:

Tuesday, December 8, 2015

Salesforce: Export non-English characters

We wrote a blog sometimes back on how to import data with non-English characters into Salesforce - Mass upload/insert non-English characters to Salesforce. UTF-8 encoding play important role when working with  non-English characters.

Salesforce by default support multi languages, so your user may enter data in their local language. When user run a report, it will show in the correct local language as well.



But, when user click Export Details to export into Excel file, it maybe shown as ???



This may caused by wrong selection of Export File Encoding, to support Non-English characters, make sure to select Unicode (UTF-8) when you export data export into excel.



Screenshot below would be the correct result exported to Excel file.




Sunday, December 6, 2015

Salesforce: Mass Update from List View using JavaScript

Sometimes back, we discussed on how to update Salesforce with JavaScript from a button in a page layout. Next, recently we have issue on how to replicate the same for many records to mass update from list view? Inline Editing in one the option to mass update records from a list view, read this blog for more information on how to use inline editing in list view.

But how about if we always need to mass update with the same data? It can be for only 1 field or for multiple fields, example: update Account type to Customer. Using inline editing may not always be the best option with all the limitations of inline editing.

Solution:
We can use similar approach of using JavaScript to mass update many records from list view.
1. Create custom button with Java Script
2. Add the button to list view

For this blog, we will use scenario to mass update Account type to Customer.

1. Create custom button
  • Navigate to Setup | Customize | Accounts | Buttons, Links, and Actions
  • Click New Button or Link
  • Enter Label, select Display Type = List Button and enable Display Checkboxes (for Multi-Record Selection), Behavior = Execute JavaScript, Content Source = OnClick JavaScript
  • Copy and paste following script
 {!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")}  
 var records = {!GETRECORDIDS($ObjectType.Account)};   
 var updateRecords = [];   
 if (records[0] == null)   
 {   
  alert("Please select at least one Account")   
 }   
 else   
 {   
  for (var i=0; i<records.length; i++)   
  {   
   var acc = new sforce.SObject("Account");   
   acc.id = records[i];   
   acc.Type = "Customer";   
   updateRecords.push(acc);   
  }   
  result = sforce.connection.update(updateRecords);   
  window.location.href = "/001";   
 }  




2. Add the button to list view
  • Navigate to Setup | Customize | Accounts | Search Layouts
  • Click Edit on Accounts List View
  • Select the custom button created and move it to the right on Selected Buttons
  • Save and done



Note: if the record unable to save for some reasons, maybe validation rule, the error message will NOT display and user may not aware. But, admin can debug this with Debug Log.


This operation will consider as "Api" with Application pointing to the custom button id.



Wednesday, November 25, 2015

Salesforce: Cross Filter disabled in Report

Cross filter is one of the most useful feature when you are looking for exception report, such as: Open Opportunities without Activities. But, if for some reason you find not able to use Cross Region as screenshot below.


You may see it when using custom report type, no matter the primary object is related to a child object or not. It is caused by the standard ID field not included in the available fields for reports.

With adding ID field as available field in report, for example Opportunity ID for primary object = Opportunity, Account ID for primary object = Account, and so on, will make Cross Filter available again, therefore this is not related to child object.

To add the ID field, navigate to Setup | Create | Report Types, look for the report type name, and click Edit Layout button at Fields Available for Reports and add ID from the primary object for that report type.


Monday, November 23, 2015

Salesforce: Cannot edit Dashboard

This blog only applicable for Salesforce org have "enable access levels for sharing report and dashboard folders", which is enhanced version of the report/dashboard folder sharing.


Recently we have a super user not able to edit a dashboard (Edit button is not visible for the user), although user have View All Data and Manage Dashboards in Public Folders permissions, and user also have Editor access to the dashboard folder. Enable Manage Dashboards in Public Folders permissions will auto enable following permissions:
  • Create Dashboard Folders 
  • View Dashboards in Public Folders
  • Edit My Dashboards

After thorough finding, the dashboard is a dynamic dashboard created by other super users, so user is
in the same role hierarchy. The super user also already have Manage Dynamic Dashboards permission.

Latest finding, it is caused by View My Team's Dashboards permission is not enable for the user. To investigate why a user not able to edit a dashboard in organizations using enhanced folder sharing. Users can edit some dashboard details and save the changes as the current running user of the dashboard. They will be restricted to which details they can modify if they are not the running user of the dashboard. To ensure complete access, the profile permission View All Data must also be granted.

Items below when user do not able to edit a dashboard:
1. The user must be Editor or Manager access to the dashboard's folder
2. The user must have the following permissions:
  • Run Reports
  • Create and Customize Dashboards
  • Manage Dashboards in Public Folders
  • Manage Dynamic Dashboards is requested to edit Dynamic Dashboards
  • View My Team's Dashboards is requested to edit Dynamic Dashboards

Reference:


Sunday, November 22, 2015

Salesforce: Password Policies and Session Timeout

Salesforce provide ability for administrator to define Password Policies and Session Timeout for their organization. Navigate to Setup | Security Controls | Password Policies to define organization password policies, from: expiry days, remember password history, minimum password length, password complexity, maximum login attempt, lockout period and so on. While Session Timeout is configured from Setup | Security Controls | Session Settings.



But, you also may notice that you can find Password Policies and Session Timeout in Profile setting.


So, which policies and setting will be applied to users and why there are two settings for the same thing? Since Winter '15, Salesforce provide finer control over the user experience by Profile, while earlier available setting at Security Control applied to the entire organization. The settings for session duration and password policies at the profile level override the settings at the organization level.

Note:
  • When you setup Salesforce initially, Profiles password policies and session timeout setting will follow setting from Security Control.
  • When you change password policies and session timeout at Security Control, it will apply to all Profiles setting, as long as setting in Profile haven't change manually.
  • You can manually change password policies and session timeout at Profile different with Security Control, and users assigned to this profile will follow setting in Profile rather than Security Control
  • Once you change the setting in Profile differ with Security Control, any changes in Security Control will NOT apply to setting in Profile anymore.
  • When you create a new custom profile, it will follow setting from Security Control, changes in Security Control will apply to the new custom profile, until you manually change in that profile.
  • When you clone a profile with password policies and session timeout has been modified, to a new custom profile, password policies and session timeout in the new profile created will copy from Security Control, not from the original profile used to clone.
  • A custom profile has been changed manually will not able to sync with Security Control setting anymore, even you manually align it with Security Control setting, it will not sync again when Security Control setting changed.

Reference:


Page-level ad