Pages

Tuesday, November 26, 2013

Salesforce: Freeze API

Six months back, I wrote this blog to disable user login to SFDC temporary, maybe for major internal release.

In Winter '14 release, Salesforce introduce Freeze user feature. Administrator can easily freeze user, so he/she will not able to login to Salesforce temporary. But, if you have 500 users to freeze, it is not a nice job to open each user and click Freeze button.

Luckily, Salesforce provide API for this. It is a field called IsFrozen, located in a new object, called UserLogin. You only can see this object using API version 29.0 and above, so if you use Data Loader, make sure it is version 29.0 and above. You can query and update this object, but not create and delete as it will sync to User object.

Screenshot from Data Loader














SOQL to this object using Developer Workbench
SELECT Id, IsFrozen, IsPasswordLocked, LastModifiedById, LastModifiedDate, UserId FROM UserLogin















Monday, November 25, 2013

Salesforce SOQL query LAST_WEEK ; LAST_N_DAYS:n ; N_DAYS_AGO:n


LAST_WEEK
Using criteria LAST_WEEK in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) on the first day of the week before the most recent first day of the week and continues for seven full days. The first day of the week is determined by your locale.
For example, my user locale setting is English (United States) and today = Sat, 23 Nov 2013, I run the query below:
SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate = LAST_WEEK ORDER BY CreatedDate DESC
this query will return accounts created between 10-16 Nov 2013, because for Locale is US English, a week runs Sunday to Saturday, whereas with UK English, a week spans Monday to Sunday.

SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate < LAST_WEEK ORDER BY CreatedDate DESC
this query will return accounts created before 10 Nov 2013.

LAST_N_DAYS:7
Using LAST_N_DAYS:7 in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) of the current day and continues for the last 7 days.
SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate = LAST_N_DAYS:7 ORDER BY CreatedDate DESC
If today is Friday, 22 Nov 2013, using LAST_N_DAYS:7 will return the account created between 16 - 22 Nov 2013, while LAST_WEEK will return the account between 10 - 16 Nov 2013.

N_DAYS_AGO:7
Using N_DAYS_AGO:7 in SOQL will return all records where the date starts from 12:00:00 AM (user Local Time Zone) on the day 7 days before the current day and continues for 24 hours. (The range does not include today.)
SELECT Id, Name, CreatedDate FROM Account WHERE CreatedDate = N_DAYS_AGO:7 ORDER BY CreatedDate DESC
If today is Monday, 25 Nov 2013, using N_DAYS_AGO:7 will return account only created on 18 Nov 2013. 


Please note all Date field returns in the SOQL query will be in GMT format, for example, 2013-11-18T08:05:21.000Z, so you need to convert it as needed.


Sunday, November 24, 2013

How to show only top X values in Salesforce Dashboard ?

By default, Salesforce Dashboard will show all values in Vertical Bar Chart, Horizontal Bar Chart, Line Chart, Pie Chart, Donut Chart, Funnel Chart, Scatter Chart, and Table component. Component below show All Chatters Group with number of members for each Group.

But, how to show just top 3 group with most members? It is easy in Salesforce:
  1. Edit the dashboard
  2. Click 'Edit Attributes' icon
  3. Go to 'Formatting' tab
  4. Look for Maximum Values Displayed and enter 3
  5. Make sure select Sort by Value Descending
  6. Once you move your mouse cursor out of that field, you will notice preview at the right change to 3
  7. Click OK 
  8. Done

You can use the same way to show top 10 Sales Rep, or top 5 area with minimum claim, etc.



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).

Friday, November 15, 2013

New Salesforce.com Certified Logos

Just one week before Dreamforce '13, Salesforce introduce new logos for Salesforce.com Certified Professional.





This is Salesforce.com certificates currently I hold:




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