Pages

Monday, April 22, 2013

Salesforce: Campaign field not show in Lead page layout

A user come to me and ask, "Why the Campaign field in Lead page disappear after create a new lead ?"

Hmmm... as system admin, what will you check?
  • Make sure Campaign field is added in Lead page layout - checked
  • Check Field-Level Security for particluar user profile - checked

User still do not see Campaign field in Lead after it saved or when user edit a Lead, but it is visible when user create new Lead. After some finding, it is designed by default from Salesforce.

Here is the explanation:
1. The Campaign lookup field on the lead page only available when user create new Lead.




2. It will disappears after a new lead is created, because the purpose of this field is to make it easier for the user when creating a new lead and to associate it to an existing campaign.




3. If a campaign is associated from this lookup field on Lead creation process, it will be shown in Campaign History related list. User can add more campaigns from Campaign History related list in Lead Page layout.



If we look to the data structure, Lead Id is a field in CampaignMember object, Setup | Customize | Campaigns | Campaign Members | Fields

When a Lead is converted, the most recently associated campaign is brought over to the Opportunity Campaign Source field upon conversion.


Reference: Why does the Campaign lookup field on the lead page disappear after a new lead is created?




Sunday, April 14, 2013

Salesforce Global Variable

In previous blog, we talk about Custom Label, where System Administrator able to set values in Custom Label, it is accessible via formula field using $Label. $Label is one of Global Variable in Salesforce, you can use global variable to reference general information about the current user or your organization. Global variable can be easily identified with prefix $.

Components such as custom buttons, custom links, formulas, and Visualforce pages allow you to use global variables with special merge fields to reference the data in your organization. Please note, global variables accessible in formula field, validation rule and custom link / button are different. See screenshot below:

in formula field











in validation rule











in custom button / link




















Here a few often used Global Variable merge field for validation rule or formula field:

$Profile -- A global merge field type to use when referencing information about the current user’s profile. Use profile merge fields to reference information about the user’s profile such as license type or name.

$User -- A global merge field type to use when referencing information about the current user. User merge fields can reference information about the user such as alias, title, and ID.

$RecordType -- A global merge field to use when referencing the record type of the current record.
Although this merge field is not visible in screenshot above, but it will work. You can use following merge fields: $RecordType.Id, $RecordType.Name

$Organization -- A global merge field type to use when referencing information about your company profile. Use organization merge fields to reference your organization’s city, fax, ID, or other details. If you use this merge field with $Organization.Id and reference to your production instance, when you create/refresh sandbox, Id value in the validation rule will change to new sandbox Org Id.


Some use cases using Global Variable:

1. To ensure that only the record owner or users with profile System Administrator can make changes to Opportunity Amount.
Create validation rule in Opportunity with following Error Condition Formula:
AND( ISCHANGED( Amount ), Owner <> $User.Id, $Profile.Name <> "System Administrator" ) 

2. Not allow users with profile System Administrator or users with first name = Steve to create or modify Account
Create validation rule in Account with following Error Condition Formula:
OR($User.FirstName = 'Steve', $Profile.Name = 'System Administrator')

3. To view all Account last modified by me (assume Account sharing Organization-Wide Defaults is Public)
Create a checkbox formula field "Last Modified by Me" in Account with formula:
$User.Id = LastModifiedById

"Last Modified by Me" value will be dynamic based on current login user. Then, create a List View with filter "Last Modified by Me" = True (the same can be applied for Report).

You can share this view to all users or certain groups of users without each user need to create their own view for the same purpose.

This kind of simple formula can be used for Created By Me or any user lookup custom field in any object.


Reference:


Salesforce Custom Label

Custom Label maybe not so popular among Salesforce administrator compare to other feature, such as: workflow, formula field and so on, even less popular compare to Custom Setting. Custom Label also enable admins or developers to show data/value in multi-language.

Custom Label may be more popular for developers to store a variable, but Custom Label actually also available for system administrator to be used in formula field, workflow rule, and validation rule. For a formula field that refer to custom label, value of the formula field will be depend on value from custom label referred, when display in page layout or report, it will be displayed based on language selected in user detail.

To create Custom Label, click Setup | Create | Custom Labels. You only can add translation language based on languages supported in your Translation Workbench.



Once created, you can find Custom Label in Global Variable start with $Label



Once added in formula field or other places, it will show with format $Label.Label_Name



Custom Label enable developers to create multilingual applications by automatically presenting information in a user's native language from Apex class or Visualforce page.

For Apex class, it would be just a simple as: String strMyLabel = Label.Hello;


Note: if you want to set Custom Label in multi-language, you need to enable Translation Workbench. To enable Translation Workbench from Setup | Translation Workbench | Translation Settings, then add and activate languages that you need.


Reference: Custom Labels



Thursday, April 11, 2013

Delete Campaign in Salesforce


Background: a user come to me that she does not see Delete button, she would like to delete a campaign created by mistake.

As usual, I check user profile and page layout:
- User Profile have Delete permission on Campaign object - checked
- Page Layout have Delete button - checked
So, what is the caused ...?

Finding.... Campaign is not the same with other objects. You need to enable Marketing User permission selected in the user detail. Once enabled and both items above checked, the user should see 'Delete' button for Campaign, the same for 'New' button to create Campaign.

From Setup | Manage Users | User | look for user | Edit | enable Marketing User | Save


Marketing User permission in user detail allows a user to manage Campaigns, users with enabled Marketing User checkbox has the right to create and manage campaigns, including:
  • Create a new campaign
  • Edit an existing campaign
  • Delete an existing campaign
  • Update campaign statistics
  • Import leads into a campaign*
  • Mass update the status for members of a campaign*
  • Configure advanced campaign setup to define member status values
  • Change the campaign member type
  • Run campaign reports across multiple campaigns
  • Add Contact and Lead to Campaign from a report using Add to Campaign

* In order to use the campaign import wizards, the user must also have the Marketing User profile (or have "Import Leads" permission).

Create permission for Campaign object will enable:
- New button in Recent item and List Views
- Clone button in Campaign Page Layout

Edit permission for Campaign object will enable:
- Edit Campaign link in Recent item
- Edit button in Campaign Page Layout
- Manage Members (with: Add Members - Search & Edit Members - Search option) in Campaign Page Layout


Reference:


Saturday, March 30, 2013

Salesforce: Change Account Owner


Do you realize when account owner is changed using Salesforce.com UI, the new owner will also gain ownership of:
  • All Notes and open Activities for the Account (completed Activities will not be transferred)
  • All Contacts tagged to the Account owned by old owner
  • All open Opportunities tagged to the Account, including closed Opportunities if you select the Transfer closed opportunities, and Opportunities owned by other owner if you select Transfer open opportunities not owned by the existing account owner, see screenshot below:

Above scenario will also correct for mass transfer from Setup | Data Management | Mass Transfer Records | Transfer Accounts.

But, if  you change Account owner through API, or API tool such as: Data Loader, only the Account Owner will be change, it will not change owner of Contact, Opportunity and other objects related.


Reference:

Last Update: 17 May 2016

Thursday, March 28, 2013

Salesforce: Formula field best practice


Formula field in Salesforce is great feature for user, it simplify complex filter conditions for SOQL queries, list views, and reports.

Let's say we have CloseDateAge formula field, we can use it in report filter CloseDateAge range = Current FY.

Or in SOQL
SELECT Id, Name
  FROM Opportunity
 WHERE CloseDateAge__c >  14
   AND CloseDateAge__c <= 21

Everyone is happy because they can get the data they need with very little effort, right? Wait a minute.

Indexes
By default, formula fields don’t have indexes. So when you create and use a formula field such as CloseDateAge with very large objects (say, objects that have more than one million of records), the SOQL queries and reports using the formula field as a filter might perform slower because your queries and reports have to perform full scans to find target records.

You can workaround by create trigger or workflow to update a field. It's work, but it requires overhead and is not intuitive.

Since the Winter ’13 release, you have been able to contact salesforce.com Customer Support to create a custom index on a formula field, provided that the function that defines the formula field is deterministic. But, Salesforce cannot index formula fields that:
  • Reference other entities (i.e., fields accessible through lookup fields)
  • Include other formula fields that span over other entities
  • Use dynamic date and time functions (e.g., TODAY, NOW)
A formula is also considered non-deterministic when it includes:
  • Owner, autonumber, divisions, or audit fields (except for CreatedDate and CreatedByID fields)
  • References to fields that Force.com cannot index:
  • Multi-select picklists
  • Currency fields in a multicurrency organization
  • Long text area fields
  • Binary fields (blob, file, or encrypted text)
  • Standard fields with special functionalities:
  • Opportunity: Amount, TotalOpportunity, Quantity, ExpectedRevenue, IsClosed, IsWon
  • Case: ClosedDate, IsClosed
  • Product: Product Family, IsActive, IsArchived
  • Solution: Status
  •    Lead: Status
  •    Activity: Subject, TaskStatus, TaskPriority

The CloseDateAge field above is a perfect example of a non-deterministic formula field that Force.com cannot index. So what can you do when you can’t create an indexed formula field to hide complex filter logic? Go back to square one: Put your filter logic in your filters!

So, in the SOQL above, change it to
SELECT Id, Name
  FROM Opportunity
 WHERE ((CloseDate = LAST_N_DAYS:21)
   AND  (CloseDate < LAST_N_DAYS:14))


Page-level ad