Wednesday, April 11, 2018

Salesforce: Account accessibility

As we mentioned in this blog Contact, Opportunity, Case access, Role Hierarchy play a part in giving Account owner accessibility (view or edit) of Contact, Opportunity, and Case tagged to the Accounts owned by the user.

However, how is the other way round, if the Opportunity (including Contact and Case) is not the same with the Account owner, can the Opportunity owner able to access Account where the user supposed not able to access that account?

The answer is yes, this is called implicit sharing. Salesforce provides implicit sharing between accounts and child records (opportunities, cases, and contacts), and for various groups of portal users.

  • Access to a parent account — If you have access to an account’s child record, you have implicit Read Only access to that account.
  • Access to child records — If you have access to a parent account, you have access to the associated child records. The account owner's role determines the level of access to child records, read this blog Contact, Opportunity, Case access.

However, this does not apply to lookup relationship for custom objects.

If you are still in Classic, you can check the sharing reason, read this blog Sharing Button URL. This implicit sharing will be shown with reason as "Associated record owner or sharing", if you click that link, it will show which records that associated and give the user access to the parent record.

Click "Associated record owner or sharing" link, in this sample, I click "Allison Wheeler".


Saturday, April 7, 2018

Salesforce: App Visibility and Query

This blog is written for Apps in Classic, not Lightning apps.

To check app visible and set to default for a user, go to the User Profile, and looks for Custom App Settings.

But, as you may know, in addition to Profile, admin also can assign the user with Permission Set, and additional apps can be added from Assigned Apps.

So, if you would like to trace down apps visible for a user, check user Profile + Permission Set assigned.

App Visibility 
To check an app is enabled for which profiles, open the app page, and click Edit button, scroll down to the bottom and check for Assign to Profiles section, users in the selected Profile will able to see the app.

With SOQL, we can query for more apps and profile/permissions set.

1. AppMenuItem
This object store item in the app menu.
Sample query: SELECT Id, ApplicationId, Name, Label, NamespacePrefix, IsAccessible, IsVisible FROM AppMenuItem WHERE Type = 'TabSet' ORDER BY ApplicationId

Id - 0DS prefix
ApplicationId - this is the app Id (prefix 02u)
Label/Name - app label and API name
NamespacePrefix - usually part of a managed package
IsAccessible - if true, the current user is authorized to use the app
IsVisible - if true, the app is visible to users of the organization

2. SetupEntityAccess
When granting a user access to an entity, associate the appropriate SetupEntityAccess records added with PermissionSet that’s assigned to a user.
Sample query: SELECT Id, SetupEntityId, ParentId, Parent.Label, Parent.IsCustom, Parent.IsOwnedByProfile, Parent.ProfileId FROM SetupEntityAccess WHERE SetupEntityType = 'TabSet' ORDER BY SetupEntityId

Id - 0J0
SetupEntityId - this is the app Id (prefix 02u)
ParentId - this is Permission Set Id (prefix 0PS), it can be Profile or Permission Set, check field IsOwnedByProfile. You can use parent relationship queries with . (dot)

By combining the 1st query on AppMenuItem and 2nd query on SetupEntityAccess using Application Id (prefix 02u), you can relate app accessibility with profile and permission set.

Sample: you would like to check all profile and permission have access to Sales app.
1. Query AppMenuItem to get Application Id for Sales app
2. Query SetupEntityAccess to get the list of Profiles and Permission Set for that application id (looks for SetupEntityId)

To enhance this, you can query to object PermissionSetAssignment to get users able to access the app, check out this blog Using Permission Set to Query User Permission.


Wednesday, April 4, 2018

Salesforce: Change User Email Address

Whether you’re a Salesforce user or Salesforce admin, you can change the email address in the details on User records to update contact information.

Requirement: Email addresses can only be updated for Users listed as “Active” on the User Detail page.

Once email change in the setup menu, a notification email will be sent to the original email address and a verification email will be sent to the new email address to authorize the change. To apply the update, the user must click the verification link sent to their new email and complete the resulting verification steps within 72 hours.

Please note that this will happen when changing the email address on the user record, including changing the "return address" from the user's personal email settings.

Expected Behavior:
When these fields are updated, you can expect the following:
  • Username: the field is updated and the user receives an email notification, notifying them of the change.
  • Email Address: an email is sent to the new email address so that the change can be confirmed. The field is not updated until the email address owner confirms the change. An email is also sent to the older email address informing the change.
  • Return Email Address: an email is sent to the new email address so that the change can be confirmed. The field is not updated until the email address owner confirms the change.


Tuesday, April 3, 2018

Salesforce: Formula Field to view Attachment

This blog is more for Classic, as the attachment is no longer support in Lightning, although existing attachments will be still available in Lightning, you just can't upload the new attachments in Lightning.

Here is the requirement, users would like to have the ability to view the attachment within one click from record page layout, assume only max 1 attachment per record.
By default, you need to scroll down to the "Notes & Attachments" related list, then click the file name, this will open attachment page (00Pxxxxxx), which also show the file size, then click "View file" link -- this is two click from the record page.

Using formula field below, it will show View link when the "id" is available, otherwise, the View link field will not be visible.

IF (NOT(ISBLANK(Attachment_Id__c)),HYPERLINK("/servlet/servlet.FileDownload?file="+ Attachment_Id__c,"View", "_blank"),NULL)

This is to assume that Attachment_Id__c value (a custom text field) has been populated by apex trigger.

The above formula field will work in Lightning, but "_blank" target will not work; the image will overwrite existing web browser window.

Jeff's blog How to Customize Salesforce Attachments explains how to "add" custom fields for Attachment using a custom object, act as a layer between the real object with attachment.

Friday, March 23, 2018

Salesforce: Convert ID from 15 to 18 characters with Excel formula

CASESAFEID() will return 18 characters ID from original 15 characters ID, the main difference is: 15 characters ID is case sensitive, while 18 characters ID is case insensitive. The issue will arise when using 15 characters ID when your teams working in Excel for data analysis, VLOOKUP() of Excel will not work properly, as it is case insensitive, so the best is to use 18 characters ID which is case insensitive.

But, if you are not the system admin or do not have permission to create a custom field to use CASESAFEID() for case-insensitive 18 characters ID, you can copy and paste the 15 characters ID using this online tool from admin booster to produce the 18 characters ID.

The other option and this is very useful when you have a lot of rows in Excel that needs to convert the ID from 15 to 18 characters is to use Excel formula. The formula below is copied from Salesforce developer forum, just change A2 with the excel cell of 15 characters ID.


ReferenceFormula Field: calculating the 18-digit ID from the 15-digit ID

Wednesday, March 21, 2018

Salesforce: Call Flow from Action

If you check this blog again Global Actions in Lightning, Action Tyle = Flow only available in Object-Specific action, and not in Global Action. In this blog, we will share how to call Flow from an action, but will not share the basic on how to create action or how to create flow.

Use case: to increase efficiency, business users of Universal Container request the ability to update Number of Employee of Account directly from Opportunity screen.

Solution: create a flow and call it from Action.

1. Create Flow
Make sure the flow must be active and have screens, so it can't be Autolaunched Flow. Flow actions let you pass the value of the record's ID field into the flow, but that's it. Your flow needs to have a variable with Text Input called recordId, the action passes the record's ID into that variable at runtime.

see all items in Explorer panel

1st box - to get Account Id. Remember this Flow will be located in Opportunity so the variable "recordId" will return would be Opportunity Id, not Account Id. In short, this box is to query Account Id from Opportunity object.

2nd box - to get Account Name and Number of Employee. Use Account Id return from 1st query to retrieve Account Name and Number of Employee from Account object.

3rd box - in this box, the user will enter Number of Employees to update into Account, but to make it nicer, we can display Opportunity Id, Account Id, Account Name, and pre-populate Number of Employee in the textbox for user to update.

4th box - this box will save Number of Employee from screen to Account object.

2. Create Action
Create new Action with Action Type = Flow.
Select the Flow created in step 1.
Add the action to "Salesforce Mobile and Lightning Experience Actions" panel in Opportunity Page Layout, in Lightning this action will become a button, while in Salesforce mobile app it will become an icon in action bars.

3. Showtime
Now open an opportunity, you should notice a button called "Update Acct Employee".
Click the button, it will show Account Id, Opportunity Id, Account Name and pre-populate existing Number of Employee from Account.

Lightning Experience

Salesforce mobile app

I am not sure if this is a good use case because you can get something almost similar using action type "Update a Record", check this blog Update Parent Record with Action, but if your screen have logics that need query, or with multiple screens, a single "Update a Record" action will not able to  handle it, calling a Flow from an action would be a better options.

- Update Parent Record with Action
- Global Actions in Lightning
- Flow Action Considerations
- Launch a Flow from an Object-Specific Action