Pages

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


Wednesday, March 27, 2013

Tips on Analytic Snapshots

click image for higher resolution image

Salesforce: Activities Archived

One day, a user comes to me, "Why I do not see some of my activities in the report, although they are visible in the page layout related list from an object"?

This is because Salesforce archive activities (tasks and events) that are over a year old, for activity with criteria:
  • Events with an ActivityDateTime or ActivityDate value greater than or equal to 365 days old
  • Tasks with an IsClosed value of true and an ActivityDate value greater than or equal to 365 days old
  • Tasks with an IsClosed value of true, a blank ActivityDate field, and created date is greater than or equal to 365 days ago

If you are using Data Loader, you need to select Export All instead of Export, and if using other API tools, make sure it calls queryAll() instead of query() function.

You also can filter on the isArchived field to find only the archived records. You can update or delete archived records, though you cannot update the isArchived field. If you use the API to insert activities that meet the criteria listed below, the activities will be archived during the next run of the archival background process.

Even the activities are archived, users will still see the activities in the Lightning page (under Activities component), Salesforce does not delete the records, so you can open the activity if you have the Activity Id. 

The activities archived will no longer show in the Salesforce report and standard API call.

If you are using Einstein Analytics dataflow, archived records will not be retrieved from the sfdcDigest node, feel free to vote this idea.


Last updated: 7-Jan-2021

Tuesday, March 26, 2013

Salesforce: Account Team Member and Account Share

Account Team Member and Account Share only available in Enterprise and Unlimited edition (included Developer edition). An account team is a team of users that work together on an account. You can add a user into Account Team manually from Account Team related list in the Account Page Layout.


After click Add button, you can specify Account Access, Contact Access, Opportunity Access, Case Access, and Team Role. If your default sharing in OWD is Private for that object, you will see Private, Read-Only, and Read/Write options in the picklist. You can add up to 5 users every time you add team members manually. 


But, the manual process is not fun when you need to add users into hundreds of account team members. So, here is the solution, use Data Loader to mass create AccountTeamMember records and AccountShare records.

1. Account Team Member
The API name is AccountTeamMember, you need to populate the following fields when mass inserts into AccountTeamMember: 
- AccountId
- UserId
- TeamMemberRole

Note: creating this record will not allow users added into AccountTeamMember to access Contact, Opportunity, Case if the sharing setting is Private. TeamMemberRole value can be different from values defined in Team Role. 

Purpose: it will show user added to Account Team related list.

2. Account Share
The API name is AccountShare, you need to populate following fields when mass insert into AccountShare: 
- AccountId
- UserOrGroupId
- AccountAccessLevel
- CaseAccessLevel [optional]
- ContactAccessLevel [optional]
- OpportunityAccessLevel [optional]
You can set Private, Read-Only, and Read/Write in the above fields optional if default sharing in OWD is set to Private.

Note: user added into Account Share will access Case, Contact, and Opportunity records with  Read-Only or Read/Write permission, even if it is not shown in Account Team related list.


Here is more information on mass create manual sharing rules with the Data Loader, click here.


Mass upload/insert non-English characters to Salesforce


We can mass upload / insert data to Salesforce easily using Data Loader or other API tool. But, if we get the data in Excel file with non-English characters, non-English characters will be come ??, This  is happened if we save the CSV file directly from Ms Excel.

To upload in non-English characters correctly, the file should be in UTF-8. Here step by step needs to be done, to avoid Ms Excel limitation in process non-English characters.

[ MS Excel ]
1. Open the *.xlsx file from MS Excel
2. Click File | Save As
3. Give a file name and choose "Unicode Text (*.txt)" for "Save as type :" and click Save

[ MS Notepad ]
4. Open the unicode text file using Microsoft Notepad. Some characters can appear as a box. This is because Notepad cannot display some unicode characters, but you can ignore it at this point.
5. It must be the tab delimitered file. Replace tabs with comma (,)
- Select tab character by dragging the character between two column headers and press Ctrl+C
- Replace all tab characters with comma using Replace function (Ctrl+H)
6. In Notepad, click Save As
7. Give a file name and change Encoding: to "UTF-8"
8. Click Save.

[ Windows File Explorer]
9. Change the file extension from "*.txt" to "*.csv". The file icon should be changed to MS Excel now. If it is not changed, check Windows Folder options. (Windows Start menu > Control Panel > Folder Options > View tab > uncheck "Hide extensions for known file types"). This will show the file extensions. Try changing the file extension again.

[ MS Excel ]
10. Open this CSV file from Excel and verify if the data is okay.
*** If you find any problem in this step, you should NOT save the file from Excel. It will cause the encoding problem!! Just check the data only in Excel. If you see a data problem at this stage, fix the data from the original spreadsheet and repeat the steps again. Or, you can change it from Notepad but should ensure that the file is saved as UTF-8 format.

You can download sample csv file with non-English characters saved in UTF-8 encoding here.

Page-level ad