Thursday, November 29, 2012

Record Type in

If you are using with Enterprise, Unlimited and Developer edition, Record Type is a powerful feature. We can define business processes, picklist values, and page layouts to different users based on their profiles. So, even for the same object, user can have different page layout with different fields, different picklist value and etc.

But, sometimes admin overkill of Record Type usage. Not all condition need to use record type, may be a custom picklist field is enough. Please note that record type is different with a normal custom field and you cannot just edit record type like normal picklist field.

So, when do you need to setup record type?
1. Different Page Layout
Same user need to see different page layout based on a type. User will see different field position, required fields, buttons, related list for the same records.

2. Different Picklist Value
Configure available values in picklist field depends on the record type.

3. Assign record type only for certain profiles
We can set available record type and default record type for each profile.

This is some scenario you do not need to setup record type actually
1. Use as Type picklist
This is very bad, do you notice once you have record type, when user create new record, they have to select a record type before come to the main screen, so please plan ahead correctly.

2. Page layout usage
Not always need to have record type to differentiate user not see some fields in page layout. Admin can adjust using field level security, so some profiles will NEVER see that field, in page layout, report, etc.

Once you have more record type, it is more effort need to maintain, so if possible use less record type.

Here link to record type cheat sheet from

Sunday, November 18, 2012 Queue SOQL

Queues allow groups of users to manage a shared workload more effectively. A queue is a location where records can be routed to await processing by a group member. The records remain in the queue until a user accepts them for processing or they are transferred to another queue. You can specify the set of objects that are supported by each queue, as well as the set of users that are allowed to retrieve records from the queue.

Queues available in almost all edition, from: Contact Manager, Group, Professional, Enterprise, Unlimited, and Developer. Queues can be created for Leads, Cases, Knowledge article version, Service contract and custom object which not a child object in a master-detail relationship.

SOQL to query all queue:
Select g.Id, g.Name, g.Email from Group g where g.Type = 'Queue'

A queue can assign into one or  many objects, here SQOL to retrieve object assigned in a queue:
Select q.Id, q.QueueId, q.Queue.Name, q.SobjectType from QueueSobject q

Note: you can you Apex Data Loader to mass insert or mass update the data in Group and QueueSobject object.

Click here for help link for queues overview.

Wednesday, November 14, 2012

Salesforce: Custom Button to pre-populate Fields

Out-of-the-box, when we create a new record from a parent object related list, provide parent name pre-populated in child object. This is efficient and save time, user do not need to look for the parent record again.

This is good, but, often we need more fields to be pre-populated for some scenario and make our (read: Salesforce users) life easier :)
We can make this happen by create new custom button whether in related list or in page layout. In this sample, we'll use Account as parent and Opportunity as child.

NOTE: This is considered a URL hack and it is not supported by Salesforce. Using undocumented query strings is absolutely discouraged as Salesforce can change them at any time without notice.

Custom button in page layout
Go to Account object in Setup menu and choose Buttons and Links. Click New button and select option as screenshot below. Once button created, you need to add the button into Account page layout.

Custom button in related list
Go to Opportunity object in Setup menu and choose Buttons and Links. Click New button and select option as screenshot below. Once button created, you also need to add the button in Opportunity related list in Account page layout.

OK, now we understand how to create the custom button, but what is the URL??? Here we go...

If you click Opportunity button in related list, see the URL

So, what is the parameters and values? Let's parse it:

In this sample there is record type in Opportunity and we want to skip Record Type selection page when user click new Opportunity by populating Record Type Id in the URL. So, this would be the URL:

Now, we want to pre-populate other field from Account. Here we go... you need to find out the Id of textbox from web browser, in page edit the record and right click at textbox then select Inspect element

Once you get the id, add it into the URL:

Custom object
Parameter for pre-populate for lookup to an custom object id different, see sample below:

Let's parse it:{object_prefix}/e?CF00N900000022p5z={parent_object_name}&CF00N900000022p5z_lkid={parent_object_id}&saveURL=/{parent_object_id}&retURL=/{parent_object_id}

Notice that parent name is CF00N900000022p5z and parent id is CF00N900000022p5z_lkid and a new parameter saveURL to redirect the page after user hit Save button.

Before you add more and more fields pre-populated, please consider this:
  • Sometime, if field in child object is not edit-able, consider to use formula field in child object
  • If the field do not need to copy from parent, you can hardcode it into the URL
  • To pre-populate data with some logic, you need visualforce page with apex code.

Video created by 'Christian Deckert' is simply good to guide you step-by-step in creating URL for your custom button.

Some of you may looking for a way to autosave the record, Salesforce used to support parameter save=1, but for security reason to prevent Cross-Site Request Forgery (CSRF), this parameter has been removed.
You may look for AJAX toolkit to update + save record from a button.

Tuesday, November 13, 2012

Field Tracking

Out-of-the-box, provide field tracking for up to 20 fields for standard and custom object. For custom object, you need to enable it by edit the object enable "Track Field History".

Once enabled, you will find a button "Set History Tracking" in "Custom Fields & Relationships" related list. For standard object, it will be there by default.

From "Set History Tracking" button, select fields you want to track up to 20 fields and yay... DONE!!

But, for Long Text Area field, it will just show who changed the field and when, that's all, no more information about what is the prior value and new value :( :(

Using Workflow and Field Update we can achieve this:
1. Create another Long Text Area to hold the history, in this sample, let's call it Response History to store history of Response (a long text area field).

2. Create a workflow with criteria ISNEW() || ISCHANGED( Response__c ).

3. Create an immediate workflow action with field update to update Response History field using this formula: 

"Last Modified: " + LastModifiedBy.FirstName + ' ' + LastModifiedBy.LastName + ' ' + 
TEXT(DAY(DATEVALUE(LastModifiedDate))) + '/' + 
TEXT(MONTH(DATEVALUE(LastModifiedDate))) + '/' + 
TEXT(YEAR(DATEVALUE(LastModifiedDate))) + ' ' + 
CASE(LEFT(RIGHT(TEXT(LastModifiedDate),FIND(" ", TEXT(LastModifiedDate))-2),2), 
LEFT(RIGHT(TEXT(LastModifiedDate),FIND(" ", TEXT(LastModifiedDate))-4),6) 
+ BR() + "------" + BR() + 
PRIORVALUE( Response__c ) + BR() + 

Please note this formula only work with user without daylight saving timezone, because it will manually parse the time from GMT to your timezone (in sample above to GMT+8), because as of now do not have TIMEVALUE() function yet. Otherwise, you can only capture the date OR display it in GMT timezone.

Here is the screenshot of the result:

Monday, November 12, 2012

Salesforce: Master-Detail relationship

Some new Salesforce admins may confuse with the different between Master-Detail relationship with Lookup relationship, since both are used to link an object to another object, and you can use parent-child relationships in SOQL queries for both relationship.

But fundamentally, it is different between Master-Detail with Lookup relationship, few items you need to notice on Master-Detail relationship:
  1. When a record of the master object is deleted, its related detail records are also deleted.
  2. The owner field on the detail object is not available and is automatically set to the owner of its associated master record.
  3. The detail record inherits the sharing and security settings of its master record.
  4. The master object field is always required in the page layout of the detail record (in child object).
  5. By default, records can’t be re-parented in master-detail relationships. However, administrator can set to allow child records in master-detail relationships on custom objects to be re-parented to different parent records, by enabling Allow re-parenting check box in the master-detail relationship definition.
  6. You can define master-detail relationships between custom objects
  7. You also can define master-detail relationships between a custom object and a standard object, but the standard object cannot be on the detail side of a relationship with a custom object. In addition, you cannot create a master-detail relationship in which the User or Lead objects are the master.
  8. You can display detail object record as custom related list on master object page layouts.
  9. You cannot create tab for a child object
  10. You can use master-detail relationships to model many-to-many relationships between any two objects. Maximum 2 master-detail relationship from a custom object.
  11. If the object is master of 1 or more detail object, you only can have 1 parent object for that object.
  12. If you have Roll-Up Summary field in parent and summarized with particular child object, when you create / update that child record, it will "edit" parent record, so if any validation rule triggered, it will stop to save when create / update child record.

Salesforce: Assign using active assignment rule

In Case and Lead, the Salesforce admin can configure Assignment Rules to automatically assign a newly created Lead or Case to a specific User or Queue. This assignment rule will trigger upon the case or lead creation, regardless of how the case or lead is created. 

The rule will also run when editing the case or lead by clicking the Edit button, however, it will not run by clicking the pencil icon on a field (vote this idea) or edit from API (such as Workbench), so this rule is ideal only for manual record creation from Salesforce web user interface.

If necessary, you can set the "Assign using active assignment rule" checkbox visible, this will allow your users to manually enable or disable the assignment rule, the "Assign using active assignment rule" checkbox will be visible on creating or editing the record (from Edit button).



How to configured?
Go to Setup | Object Manager Leads or Cases | Page Layouts, then click the Layout Properties button, then enable Default.

Case page layout

Lead layout properties

Case layout properties

Once you have the assignment rule configured, the best practice is to hide that checkbox "Assign using active assignment rule", so the rule will always run. Although in some scenarios, even if you want to let the checkbox visible, set the Default enabled by default. This checkbox is located at the far bottom of the record page, so some users may not even notice it.

How to hide the checkbox "Assign using active assignment rule"?
Untick "Show on edit page" in the page layout properties. Even the checkbox is not shown, the assignment rule will work as configured, as long as the Default in the Lead or Case Assignment Checkbox is enabled in the layout properties


Tuesday, November 6, 2012

Salesforce Hidden Features

Salesforce come with tons of features for administrator to make their live easy. But, do you know if there is more features which is not enable by default. You need to contact Salesforce support to enable it.

Here are 10 features a consultant usually needed for Salesforce implementation:

1. Ability to update Created Date and Last Modify Date

This sound crazy? But yes, sometimes you need this when do initial data migration to Salesforce. It called to enable "Audit Fields", read this article Considerations before having Create Audit Fields enabled.

2. Extended Mail Merge

With Extended Mail Merge, you can easily generate mail merge Word documents without dependency on Internet Explorer, certain Windows version, and Microsoft Word version, read this article Generating Mass Mail Merge Documents with Extended Mail Merge.

3. Person Account

For B2C companies, not all of your customer is company, instead of linking all contacts to an Account, you can request to enable Person Account. Linking all contacts to an Account will cause data skew - read this Avoid Account Data Skew for Peak Performance

4. Remove Price and Quantity field from Opportunity Product

Rather than always put 1 to quantity, you can request Salesforce support to remove price and quantity from opportunity product page layout.

5. Upgrade file attachment size beyond 5 MB

By default, user allowed to upload file to attachment maximum 5 MB per file, but we can request to Salesforce support to extend this limit to 10 MB up to 25 MB.

6. Email Relay

We can request all email send out from via our email server for audit or security purpose or etc, reach Salesforce support to can enable this feature.

7. Encrypted Field

Some confidential data, like credit card number; need to be protect. User should not able to see the information unless he is the person needed. With enabling encrypted field, admin can manage only some users able to view sensitive data, but be aware that encrypted field is not searchable and the data length is shorter.

8. Multi Currencies

Multi national companies will get most advantages once multi currency enabled. We can use it in opportunity, forecast in reports.

9. Sandboxes
Number and type of sandbox is depend on your Salesforce edition you purchased, but you can purchase additional sandboxes as needed.

10. Defer Sharing Calculations
Deferring sharing calculation is ideal if you make a large number of changes to roles, territories, groups, users, portal account ownership, or public groups participating in sharing rules, and want to suspend the automatic sharing calculation to a later time. Group membership and sharing rule calculation are enabled by default. Read this document Defer Sharing Calculations.

Sunday, November 4, 2012

Inline Editing in Salesforce List View

Salesforce allow users to edit data directly in the record page payout, but your System Administrator need to enable inline editing, all fields can be edit with inline editing except for read-only and system fields. Editable fields display a pencil icon (Editable Field) when you hover your mouse over the field, while non-editable fields display a lock icon (Uneditable Field), double the field edit it, you can edit multiple fields before hit Save button, fields has been changed but haven't save will be show in orange color and bold. 

On top of inline editing in page layout, user also can do inline editing in the List View without any effort to write any code. Many system administrators may not aware of this feature and sometimes it will not work because of some conditions needed are not fit.

Hover mouse to editable field will show pencil icon

You can use it in picklist field as well

Edit date field for multiple record at once

Here are the items need to check for inline editing in page view:

1. Enable Inline Editing and Enhanced Lists

Go to Setup - Customize - User Interface

2. Edit permission

Make sure you have edit permission to the records and object.

3. Check if any Record Type for that object?

If the object has multiple record type, you have to filter only showing one record type by adding filter criteria. So if you have 3 record type for Contact, you need to create 3 view. 

Note: you should not have more than 1 record type in the record type filter, otherwise inline editing in List View will not work.

If there is no record type for that object, you can skip this filtering.

4. Do not add Filter Logic

You are not allowed to use Filter Logic to enable inline editing in list view. 

5. Not for User object

As of now, this is not available for user object, please vote in IdeaExchange.

6. Edit multiple record at the same time

This feature is very nice if you need to edit many records to a same value. Select checkbox at the left of records and click pencil icon. Then select apply changes to all selected records.

7. Not for all fields
Some fields such as: Opportunity Amount, Stage, Forecast Category, Account Name in Opportunity is not working.

8. Not for user with Accessibility Mode enable

Make sure Accessibility Mode in user detail is disable.

9. Field Dependency

Field is not Controlling or Dependent field set in field dependency.

10. Page Layout
Make sure the field is available in a page layout, field not exist in page layout will be not work for list view inline editing.

ReferenceWhy can't I do inline editing in a List View?

Page-level ad