Pages

Wednesday, October 12, 2016

How to use Salesforce Analytics REST API for troubleshooting?

Use case: there is a report created with the same fields name, how to check if the field is come for which object easily? If we edit the report, it will not tell us the existing fields are come from which object.



Solution:

A. Using Workbench to call Analytics REST API
Documentation about this API - Salesforce Reports and Dashboards REST API.

1. Login to Workbench, select  utilities | REST Explorer

2. Execute this service /services/data/v37.0/analytics/reports/00O3B000000FiSd
change 00O3B000000FiSd to your Report Id.


3. Click Show Raw Response link.

4. Scroll down and look for "reportMetadata".


From here, we can see the 1st Created By come from Account, while 2nd Created By come from Contact.


B. Extract Report Metadata 
Use Force.com IDE or Mavensmate to open particular report metadata. Same as above, 1st Created By come from Account, while 2nd Created By come from Contact.




Reference: Salesforce Reports and Dashboards REST API 




Salesforce: Relate Contact with Multiple Accounts

In Summer 16 release, Salesforce introduces a feature to relate Contact with Multiple Accounts. The good thing is this feature is applicable for both Classic and Lightning UI, and in Salesforce1 as well. In Winter' 17 this feature even gets better, see this release notes.
  • Compact Layouts are now supported
  • Validation Rules are now supported
  • Triggers are now supported
  • Account-contact relationships can now be viewed


When you enable this feature, all of your existing relation between Contact and Account will not change, and they would become "Direct" relation - Account directly lookup from Contact will be called Direct. There will be a new related list called Related Contacts for Account Page layout, and Related Accounts for Contact Page layout.

You can see the Direct information from the new "Related Contacts" related list in Account Page layout, or "Related Accounts" related list in Contact Page layout. Personally, I would remove existing Contacts related list in Account, so users do not confuse with two almost similar related lists. You should modify Related Contacts related list to add all existing fields from Contacts and add Direct.


Setup
  • Navigate to Setup | Accounts | Account Settings
  • Enable "Allow users to relate a contact to multiple accounts"
Once enabled, you can define following actions:



Related Contacts related list from Apple Soft account page layout:



Related Accounts related list from a Contact page layout name Kim Bon:


You can add Custom field and Field Dependency for Account Contact Relationship from Setup | Customize | Accounts | Account Contact Relationship | Fields


Security Model

Add Relationship
All user (with read access to the Account) able to Add Relationship.
Click "Add Relationship" button from Related Contacts (in Account) or Related Accounts (in Contact), then fill in the account-contact relationship information.

Edit Relationship
Only user able to edit contact will be able to Edit Relationship.
Click View Rel (in Salesforce Classic) or View Relationship (in Lightning Experience) link. Then click "Edit Relationship" button.

Remove Relationship
Only user able to edit contact will be able to Remove Relationship.
Click Remove link and OK button to confirm.


Object
The object name for this is "AccountContactRelation", this is different with the old "AccountContactRole", which no longer supported in Lightning.


Reference:



Tuesday, October 11, 2016

Salesforce: Setting SSO (Single Sign On)

SSO is a process that allows network users to access all authorized networks without having to separately log in to each resource.

Salesforce can be configured as Identity Provider (IdP) using Salesforce Identity, or as Service Provider (SP).
Identity Provider is a trusted service that enables users to access other websites and services without logging in again.
Service Provider is a website or service that hosts apps and accepts identity from an identity provider.

Flow below show when user accessing Salesforce and authenticated by IdP, Salesforce is SP in this scenario.



Another flow when user accessing IdP and will be redirect to Salesforce as SP.


This blog would discuss on setup Salesforce as Service Provider and initiate SSO process:
1. User make a request to Salesforce
2. User is redirected to IdP with SAML Request
3. User authenticates & return with a SAML Response
4. Salesforce process the Response, create a session for user and return to requested resource

User open a specific my domain https://customername.my.salesforce.com, without need to enter username and password, user will be auto redirect to access Salesforce.

To setup SSO:
1. Enable My Domain in Salesforce
Refer to this documentation My Domain to create a custom domain name.

2. Enable Single Sign-On in Salesforce
Navigate to Setup | Security Controls | Single Sign-On Settings
Click Edit button "SAML Enabled"

3. SAML Single Sign-On Settings in Salesforce
In the same page as above, click New button in "SAML Single Sign-On Settings".
You need to get "Identity Provider Certificate" and upload the cert file - the authentication certificate issued by your Identity Provider.
- Identity Provider Certificate: upload cert file provided by IdP
- Entity ID: specify Salesforce base domain (https://saml.salesforce.com) or the custom domain.

4. Configure in IdP
- SAML version: only version 2.0 support for now
- Login URL: this would be Salesforce Login URL stated in SSO setting endpoints, example: https://johanyu.my.salesforce.com?so=00D90000000H7oz
- Entity ID: as defined in step 3 above
- Start Page URL: if you would like your users redirect to a specific page after login


Reference:




Thursday, October 6, 2016

Salesforce: Coding Editors

We discussed about Trigger syntax earlier. This blog, we'll continue with coding editor. To write a trigger, you need in a 'good' coding editor. Salesforce provide option of coding editors with its own benefits, from online editor within Salesforce environment until desktop application.

Please note that you can only write / edit code not directly in Production org. But you need to deploy from a sandbox or developer edition org., but we'll not discuss that in this blog.

1. Setup Menu
Setup | Customize | Object Name (such as Lead, Account, etc) | Triggers - click New button to create new trigger or Edit link to edit existing trigger.

This is the most basic editor, but also the most easiest and quickest way to code. You do not need to install anything, just login to Salesforce and make sure you have the right permissions.
When you create new trigger from here, it will provide basic trigger syntax, but no coloring, auto complete and etc. that offered by more advanced coding editor. Because as this is online coding, you need to have good internet connection.



2. Developer Console
Login to Salesforce, click your name at top right menu | Developer Console - this will open a popup window for Developer Console. Click File | New | Apex Trigger to create new trigger, or File | Open to open existing trigger.



Provide Name and select a sObject to start create new trigger.


Same as coding editor from setup menu, Developer Console is online tool so you do not need to install anything. But, compare to editor in setup menu, Developer Console have more advantages, from: color coding, auto completion, it even tell you if you have syntax error, or field not available online (see Problems tab from above screenshot).

Within Developer Console, you can run SOQL query from Query Editor, but you need to click few menu to get the object schema: File - Open - Objects - object name.



3. Force.com IDE
Follow this step to install Force.com IDE to your computer. This is the most common coding editor use by Salesforce developers. Force.com IDE is a plug-in for Eclipse to interact with Salesforce, this mean you need to setup Eclipse in your computer, then add the plug-in.

It is much more powerful then online coding editors mentioned above, on top of features offered by online editor, with Force,com IDE you can do deployment between org. (in comparison with Change Set only for org. related within a Production org.), and many more.



Although this tool is mean for developer, but admin also can take advantages of this tool to search or edit metadata, watch this on YouTube Hands-on Training: Get started with the Force.com IDE for Admins.

The only issue I always heard that this tool is pretty heavy, that's mean you need to have a powerful computer, if you are using Windows machine, you should run 64-bit OS, my experience running Force.com with 32-bit Windows machine is not really, very slow and keep hanging.

Force.com IDE offer more advanced SOQL by showing object schema.



4. MavensMate
Same as Force.com IDE, you need to install MavensMate on your computer, it is also a plug-in that you need to add on top other editor, but instead of Eclipse, with MavensMate you can choose to use Sublime Text 3, Atom, or Visual Studio Code.

Follow this link to install MavensMate. This tool is not really by Salesforce, but it is open source project. MavensMate getting more popularity recently, according to David Liu said this is the best coding editor to code Salesforce.

This tool offer about the same functionality with Force.com IDE, but in different layout and setting. 



Some user do not like Force.com IDE, because of (some items refer from An Easier Way to Delete Apex Classes From Production):
  • The Force.com IDE is very ‘heavyweight’ and is known for being quite buggy sometimes and unpleasant to use
  • They have a number of dependencies (a compatible version of Java, different IDE version etc)
  • Connectivity to Salesforce via the Force.com IDE may be an issue
  • It's very slow when you are using Windows 32-bit machine.

5. Others IDE
I'll not go to the detail for each others IDE, but here is the list:
For complete other IDE, refer to this blog by Jitendra Zaa.


Wednesday, September 28, 2016

Data.com Prospector Usage and User

When you subscribe to Data.com Prospector, each licenses user allow to importing company and contact records into Salesforce or export to CSV file with default maximum number of 300 records /month /user.

You can monitor overall usage for current month from Setup | Data.com Administration | Prospector Users




Or, you also run a report with report type "Data.com Usage", this report will show:
  • When is the transaction (created date)
  • Who is the user (created by)
  • Purchase Type (added or exported)
  • Purchase Count (number of records exported or added)

But if you want to drill-down to the details of the contacts or accounts added, that report will not show you that information.

Solution: use SOQL
There are 2 objects related to this DatacloudPurchaseUsage and DatacloudOwnedEntity.

1. DatacloudPurchaseUsage - this object will store all purchase history.
Sample query: SELECT Id, Name, Usage, DatacloudEntityType, PurchaseType, User.Name, CreatedDate FROM DatacloudPurchaseUsage WHERE Id = '09Fo0000000RZ7sEAG'



2. DatacloudOwnedEntity - this object will store each contact or account exported or added to Salesforce.
Sample query: SELECT Id, Name, PurchaseUsageId, DataDotComKey, DatacloudEntityType, PurchaseType, User.Name, CreatedDate FROM DatacloudOwnedEntity WHERE PurchaseUsageId = '09Fo0000000RZ7sEAG'




Even there is no Contact Name or Company Name recorded in this object, but there are a few pointers:
1. Data.com Key - you can match this key to match with data exported or added to Salesforce
2. DatacloudEntityType - 0 = Contact and 1 = Company
3. PurchaseType - 0 = added and 1 = export

As you see, DatacloudOwnedEntity object is a lookup to DatacloudPurchaseUsage object, via field PurchaseUsageId. For you that familiar with SOQL, as you see above queries using child-to-parent query. However, when trying to use the parent-to-child query, it is just not possible. Further check, I do not see DatacloudOwnedEntity as child relationship from DatacloudPurchaseUsage.

Screenshot of child relationship taken from DatacloudPurchaseUsage



Compare to standard object child relationship, example: Opportunity to OpportunityLineItem


Addition:
You can check users assigned with Data.com license from Setup | Data.com Administration | Prospector Users

Unfortunately, Salesforce screen does not allow you to copy-paste into Excel file nicely, but you can use SOQL to retrieve this:
SELECT Id, Name, Title, Profile.Name FROM User WHERE IsActive = TRUE AND UserPermissionsJigsawProspectingUser = TRUE ORDER BY Name


Reference:


Monday, September 26, 2016

Salesforce: Process Builder, Flow and Workflow running in System Mode

System mode: process running is NOT DEPEND on the current user permissions to the object access, field level security, sharing rule. In which the level permissions of the current user are ignored.

User mode: process running is DEPEND on the current user permission to the object access, field level security, sharing rule. In which the level permissions of the current user are enforced.

Automation in Salesforce will run in System mode, in the declarative mode this is include: Workflow, Process Builder, Process Builder + Flow. The same applicable for apex trigger as well.

While Flow will run in User mode, this is make sense as Flow is not count as automation, Flow have user interface that need user to fill something or click button.

Thanks to Mayank Srivastava for sharing matrix below this in Success Community.


The matrix is tested as of Summer '16 release, so this may change in the future. 

When Flow hit error if user do not have access to the field, an error email will be sent to the Flow creator:
Subject: Error Occurred During Flow "Flow_Name": INSERT --- INSERT FAILED --- ERRORS : (INVALID_FIELD_FOR_INSERT_UPD...

Body: An error occurred at element Element_Name (FlowRecordCreate).
INSERT --- INSERT FAILED --- ERRORS : (INVALID_FIELD_FOR_INSERT_UPDATE) Unable to create/update fields: Field_Name__c. Please check the security settings of this field and verify that it is read/write for your profile or permission set., 


Reference:

Page-level ad