Pages

Sunday, November 30, 2014

Salesforce: Opportunity Close Date changed to Today's Date

Salesforce users may experience when they close won an opportunity, the close date change to today, but that is not what the user want. What is happening? Is admin or developer write some code on this?

Let us analyse the behaviour. It is not a customization, but out of the box of Salesforce functionality, and we cannot turn it off with a checkbox tick.
  • If Opportunity Stage is not Closed Won and has Close Date in the future; when user change the Stage to Closed Won, the Close Date will automatically change to today's date
  • If Opportunity Stage is not Closed Won and has Close Date in the future; when user change the Stage to Closed Won and also change the Close Date to some other date (future or past), the Close Date will not change
  • If Opportunity Stage is not Closed Won and has Close Date NOT in the future; when user change the Stage to Closed Won, the Close Date will not change
For this scenario (item 1 above), we can use Workflow + Field Update to stop this auto Close Date change behaviour to Today's date.

Workflow:
Rule Criteria
ISCHANGED(StageName) &&
IsWon = True &&
CloseDate = TODAY() &&
PRIORVALUE(CloseDate) > TODAY()

** you cannot use Evaluation Criteria = created, and any time it’s edited to subsequently meet criteria, because ISCHANGED function is not valid with this criteria.


Field Update:
Field to Update Opportunity: Close Date
Formula Value PRIORVALUE(CloseDate)


But, since the Close Date has changed to TODAY, then we change it back to the Original Close Date, when we look at the field history, notice they are two transaction on Close Date.


Another issue with this workflow, if user have open Opportunity with Close Date in the future, when user change the Stage to Closed Won and also change Close Date to Today at the same time, system will change it back to the original Close Date, because it match rule criteria in Workflow.





Saturday, November 29, 2014

Salesforce: Opportunity Close Date on Lead Convert

When you convert a Lead into Account, Contact and Opportunity. Opportunity Close Date cannot be set from the Lead conversion field mapping.
  • If you are not using custom fiscal years, the Close Date of the newly created opportunity 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.

Use Case 1: set Opportunity Close Date = 90 days from Lead conversion date

Solution:
1. Create a Formula Field in Lead
  • Field Label = Now
  • Formula Return Type = Date/Time
  • Formula = NOW()
2. Create a Date/Time Field in Opportunity
  • Field Label = When Converted
  • Field Type = Date/Time
3. Map Field in Lead Conversion
  • Lead Now = Opportunity When Converted
4. Create Workflow in Opportunity
  • Object = Opportunity
  • Evaluate the rule when a record is "Created"
  • Rule Criteria - Opportunity: When Converted not equal to null 
5. Create Field Update Action in Opportunity for Workflow (4)
  • Object = Opportunity
  • Field to Update - Opportunity: Close Date
  • Formula Value = Today() + 90

Use Case 2set Opportunity Close Date to the first day of the next fiscal quarter.

Solution: Follow step 1-4 above:

5. Create Field Update Action in Opportunity for Workflow (4)
  • Object = Opportunity
  • Field to Update - Opportunity: Close Date
  • Formula Value = CloseDate + 1


ReferenceLead Conversion Mapping




Wednesday, November 12, 2014

Salesforce: Manage Task Notifications

In Winter '15 release, Salesforce introduce a change in Task notification to let user manage their own email notification. This is enabled by default.

Before Winter '15 release, when user create a Task, there is a checkbox Send Notification Email, if Task is assigned by other user, user who receive Task assigned do not have control to get the email notification or not.

Before Winter '15:


After Winter '15:
notice Send Notification Email is no longer exist

Admin able to deactivate this feature by navigate to:
- Setup | Customize | Activities | Activity Settings
- Deselect Enable User Control over Task Assignment Notifications
- Submit
Deactivate this restore like before Winter '15 release.

When this feature enabled, user can control Task email notification from:
- My Settings | Calendar & Reminders | Reminders & Alerts 
- In Events and Tasks section, look for option Email me when someone assigns me a task
This option is enabled by default, uncheck this will stop user to get any email when task assigned to the user.


Known issue:
"Enable Activity Reminders" in Setup | Customize | Activities | Activity Settings, must be enable, otherwise user will not see "Reminders & Alerts" under Calendar & Reminders, so cannot set option for "Email me when someone assigns me a task"


Reference:
Why I do not see the "Email me when someone assigns me a task" option under my Settings?


Salesforce.com Password reset Failure

For user forget their Salesforce login credential, user should be able to click Forgot your password? in login screen  to receive a new password via email. In many cases, admin do not need to involve at all.

Once click the forgot link and enter username, Salesforce will send email associated with user name with security question. User must answer a previously defined security question before they can reset their password and log in. If user has not defined a security question, or fails to answer the security question correctly, the password is not reset.

Once user answer the security correctly, user will get an email with a link in the email to reset password, this link will expire after 24 hours and it will active only for once, meaning user click the link then ignore it, and later user click the link again, it has been expired.

There is a maximum of five requests to change a password in a twenty-four hour period, while administrator can reset a password as often as needed.

Depend on your org password policy or profile password policy, if maximum invalid login attempts is not set to No Limit, user account will be locked after few times trial with invalid password, number of trial allowed depend on setting in maximum invalid login attempts before it locked. Resetting locked-out users’ password automatically unlocks their accounts as well.

For some reason, when administrator reset user password, we have user get email with subject: Salesforce.com password reset failure and content as below:

Dear User Name,

Your administrator has reset your password. However, your password cannot be reset at this time.

If you have any questions, please contact the salesforce.com administrator for your company.

Thank you,
salesforce.com

Root cause analysis: after hours of testing and finding, above issue happened when admin reset user password, but the user just change his password within 24 hours, or just set his password for the 1st time within 24 hours, and Require a minimum 1 day password lifetime is enabled in Password Policies setting. If this option is selected, passwords can’t be changed more than once in a 24 hour period.


Reference:

Saturday, November 8, 2014

Query User Record Access in Salesforce

Few months back, I wrote a blog to determine user record Access in Salesforce, that blog is good for admin to debug if a user not able to access or edit record. While this blog will explain how to check user accessibility to a record using query.

Use case for this functionality, such as: for a visualforce page, when user do not have edit access, Edit button will be automatically removed from the page, when user do not have read access, link to open the record automatically removed.

From API version 24, Salesforce introduce a new object called UserRecordAccess. This object represents a user’s access to a set of records. It is also only for query, not for create / delete / update / upsert. The query method also a little special compare to other standard object, you have to follow specific rule to query it:
  1. RecordId - must be selected in for query result
  2. RecordId - must be in query criteria, for RecordId you can use "=" for single record OR use "IN" to query multiple records
  3. UserId - must be in query criteria, but NOT in query result
  4. Id - you cannot query this field
  5. MaxAccessLevel value: None, Read, Edit, Delete, Transfer, All
Sample query:
SELECT RecordId, MaxAccessLevel, HasAllAccess, HasDeleteAccess, HasEditAccess, HasReadAccess, HasTransferAccess FROM UserRecordAccess where UserId = '00550000000rlrX' and RecordId IN ('0015000000TaWdI','0065000000N1CMz')

Query result:
So, one query is only for one user for up to 200 record id.

From API version 30.0 and later, UserRecordAccess is a foreign key on the records. You can’t filter by provide the UserId or RecordId fields when using this object as a lookup or foreign key.

Sample Query:
SELECT Id, Name, UserRecordAccess.HasReadAccess, UserRecordAccess.HasTransferAccess,
UserRecordAccess.MaxAccessLevel FROM Opportunity

Above query will return all Opportunity with record access for each record based on the running user. 

You can add normal filter criteria applied when you query Opportunity, sample:
SELECT Id, Name, UserRecordAccess.HasReadAccess, UserRecordAccess.HasTransferAccess,
UserRecordAccess.MaxAccessLevel FROM Opportunity WHERE Id = '0065000000N1CMz'


Known Issue: When accessing UserRecordAccess as foreign key of records, unexpected results are given. This issue does not occur when accessing to UserRecordAccess directly. Here is the detail
https://success.salesforce.com/issues_view?id=a1p30000000T4NxAAK, if you would like to be notified when issue solved, click 'This Issue Affects Me' link.


ReferenceUserRecordAccess



Sunday, November 2, 2014

Salesforce: Content Architecture

Before discussing Content in Salesforce, it is good to have a look for a few objects related to Content:



ContentWorkspace

This object label as Library in user interface with key prefix 058, it represent a public library in Salesforce CRM Content.This object is available in versions 17.0 and later. This object does not apply to personal libraries.

You cannot use API to create record in this object.

SOQL sample: SELECT Id,Name,Description,TagModel FROM ContentWorkspace


ContentVersion

This object known File in user interface with key prefix 068, it represents a specific version of a document in Salesforce Content or file in Chatter.The maximum number of versions that can be
published in a 24-hour period is 36,000. This object is available in versions 17.0 and later for Salesforce CRM Content and versions 20.0 and later for Chatter files.

This is the object you need to point to if would like to mass load document into Public Library. You can use API to mass load documents.

Sample of CSV file to mass load document:

 Title,Description,VersionData,PathOnClient,FirstPublishLocationId,TagsCsv  
 this is 301 file,"This is a test file, use for bulk upload",d:\temp\301.txt,d:\temp\301.txt,05850000000GwZBAA0,exam  

Few field need to note from this object:

FileType, when you upload document, Salesforce will determine the file type: CSV, EXCEL, LINK, PDF, PNG, TEXT, WORD, ZIP, UNKNOWN
If filetype is Link, then ContentUrl field will contain URL, this is when you add a Website link to the Library.

FirstPublishLocationId, this field refer to where the first time document publish to, it may be an object, user or a Library (which is ContentWorkspace).

ContentDocumentId & VersionId, when you load a document to ContentVersion, Salesforce will automatically create a record in ContentDocument. But, when you upload a new version of document, new record for ContentVersion will be create, but not for ContentDocument


SOQL sample: SELECT Id,ContentDocumentId,VersionNumber,Title,ContentLocation,ContentSize,ContentUrl,Description,FeaturedContentBoost,FeaturedContentDate,FileExtension,FileType,FirstPublishLocationId,IsLatest,IsMajorVersion,Language,Origin,PathOnClient,PublishStatus,ReasonForChange,TagCsv FROM ContentVersion ORDER BY ContentDocumentId,VersionNumber


ContentDocument

This object also label as File in user interface with key prefix 069, it represents a document that has been uploaded to a library in Salesforce CRM Content or a file in Chatter. This object is available in API versions 17.0 or version 21.0 and later for Chatter files. The maximum number of documents that can be published is 2,000,000.

You cannot manually create record for this object, it is control by ContentVersion.

Field to note from this object:
ParentId, Id of the library that owns the document. This record will be created automatically when you load a document or via the API for the first time. This field is available in API version 24.0 and later when Salesforce CRM Content is enabled.

For Content Document / Files in a Library, you will notice the icon when open the File


SOQL sample: SELECT Id,LatestPublishedVersionId,ParentId,Description,FileExtension,FileType,PublishStatus,Title FROM ContentDocument order by ParentId


ContentDistribution

This object is known as Content Delivery in user interface with key prefix 05D, it represents information about sharing a document. This object is available in API version 32.0 and later.

You can mass create records using API to this object.

SQOL sample: SELECT ContentDocumentId,ContentVersionId,DistributionPublicUrl,ExpiryDate,FirstViewDate,Id,IsDeleted,LastViewDate,Name,Password,RelatedRecordId,ViewCount FROM ContentDistribution


Reference:


Salesforce: Forecasting Roll-Up

This blog is refer to Collaborative Forecast, not the older Customizable Forecast, although in setup menu, it just called as Forecast only.

For org created before Winter '12 release, you need to reach Salesforce support to enable Collaborative Forecasts. To start using forecast, you have to enable all users will use forecast in user detail called Allow Forecasting, then define Forecast Hierarchy, choose one or more Forecast Types, and specify other forecast settings, such as Quota, Forecast Category, fields to display in the list of related opportunities and etc.

To enable forecast number roll-up to forecast manager in higher role hierarchy, Allow Forecasting need to be enable in the manager and all subordinate users. For user without Allow Forecasting enable, when user click Forecast tab, user will see Introducing Forecasts page only. When manager click Forecast tab, user without will Allow Forecasting enable will not shown in the Forecast tab. Navigate to user detail page to enable it.



The Forecast Hierarchy is entirely based on the role hierarchy, but you also need to specify which user is the forecast manager for each role. The forecast hierarchy is automatically generated based on your Salesforce role hierarchy. User without Allow Forecasting will not available in the forecast manager selection dropdown value. You can enable user for forecasting from forecast hierarchy, it will automatically tick Allow Forecasting in user detail level.

Only one user can be assigned as Forecast Manager in forecast hierarchy, this user will see all forecasts and adjustments from the manager's subordinates in the hierarchy roll up into his or her Forecast tab. Other user in the same forecast hierarchy will see only their own numbers.

If no user is assigned as Forecast Manager in a Forecast Hierarchy, or no users at all in the role hierarchy, the number will not roll-up in forecast to the user in higher forecast hierarchy.



For user with Allow Forecasting enabled, when they click Forecast tab, it will show 4 or 5 forecast category in the columns:
  • Quota (if you enable Show Quotas in Forecasts Settings)
  • Closed
  • Commit
  • Best Case
  • Pipeline

Omitted will not shown here as it consider has been lost. A forecast category is the category within the sales cycle that an opportunity is assigned to based on its opportunity stage. The standard forecast categories are Pipeline, Best Case, Commit, Omitted, and Closed. You can customize forecast category names for your organization from Setup | Customize | Opportunities | Fields | Forecast Category. But, you cannot add or delete them. Once the value re-label, the new label will be used in Opportunity page layout and in Forecast tab.

You can map Forecast Category value with Opportunity Stages values, so each stage of opportunity will have a direct map with forecast category which will be shown in Forecast tab. You can hide this field page layout, so user not able to manually modify Forecast Category.


Reference: