Pages

Wednesday, December 18, 2013

Deploy Salesforce Profiles with Change Set

Is it possible to deploy Profile using Change Set?
As of now (Summer '16) release, you cannot deploy Profile as stand alone component in Change Set. But, you can include Profiles in the Change Set. What this mean? Components setting (such as: custom field, custom object, etc) related to Profile will be deployed correctly for that Profile, but bear in mind that it also will deploy profile setting for Administrative Permissions, General User Permissions, Login Hours, Login IP Ranges for the profiles.

My experience in deploying Profile with Change Set is still very challenging (even we know Salesforce is keep enhance it). As Profile is not a Change Set component, it will not allow you to upload just Profile. So, if you want to deploy Profile, the workaround is to add a component to the Change Set, such as: custom field or others, then include the profile in Profile Settings For Included Components.



Below settings in Profile need be configure manually in target organization after change set deployed, if the corresponding components are not deployed in the same change set, example: you have a custom object called Invoice and profile called Sales, let's say Sales profile have Read, Create, Edit access to Invoice in source org., but if Sales profile is not included in the change set, Sales profile users will have no access to the Invoice object.
  • Standard Object Permissions
  • Custom Object Permissions
  • Field-Level Security
  • Tab Settings
  • Standard Object Layouts
  • Custom Object Layouts
  • Custom App Settings
  • Connected App Access
  • Record Type Settings
  • Apex Class Access
  • Visualforce Page Access

Following items will always deployed properly (overwrite target profile) in Profile when you include it, because it do not depend on other components:
  • Administrative Permissions
  • General User Permissions
  • Login Hours
  • Login IP Ranges

Profile not exist in target organization will be create, while existing profile will be overwritten (if the related components is in the change set). If you have a profile has been deleted in target instance, and you deploy Change Set with the same Profile name, deleted profile will be restored with all permissions before it is deleted.


Reference:

Tuesday, December 17, 2013

Salesforce: Attachments roll-up to the related Account

Do you realize that attachments on a Task or Event that is related to an Account, Contact, or Opportunity, will roll-up to appear in the Notes & Attachments related list on the Account record.

See this screenshot:

  • First attachment: related to a task in Opportunity linked to Account
  • Second attachment: related directly to Account
  • Third attachment: related to an email (which is a task) in Contact that linked to Account
  • Fourth attachment: related to Contact
  • Fifth attachment: related to an email (which is a task) linked to Account
But, they do not appear in in the Notes & Attachments for Contact or Opportunity, is this something weird?

And the worst, this is not customizeable and even to customize the related list for Notes & Attachments.

See this document related to this in Salesforce knowledge.


Thursday, December 12, 2013

Salesforce: Close Case in one click

To close a Case in Salesforce, user need to have Edit permission on Case object. By default, when a user click Close Case button, user will be bring into a new page to enter information needed before close the case. Admin can set mandatory fields at the Close Case page, from Setup - Customize - Case - Page Layout and look for Case Close Page Layouts.

But, can we make this simple? Meaning just click a button to close an open case without have to open a new page. Yes, by using custom button. Here we go:
  1. Setup - Customize - Cases - Buttons, Links, and Actions
  2. Click New Button or Link, enter Label and Name, select Detail Page Button in Display Type and Behavior select Execute JavaScript
  3. Paste JavaScript script below
  4. Add custom button created to the page layout and remove default Close Case button, you can have multiple page layout with different button based on user profile and Case record type.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
if ({!NOT(Case.IsClosed)}){
   caseObj.Status = 'Closed';
   var result = sforce.connection.update([caseObj]);
   if (result[0].success=='false') {
      alert(result[0].errors.message);
   } else {
      location.reload(true);
   }
}

Another option is to enable Closed value available in Case Status. By default, this value will be not available when user Create or Edit the Case, but we can enable it. Here we go: Setup - Customize - Cases - Support Settings, enable Show Closed Statuses in Case Status Field. This will make Closed status available when user create or edit Case, user also will not bring into Case Close page any more.

In the same Case Support Setting page, admin also can hide Save & Close button by enable Hide Save & Close Button and Cls Links.


How about if I want to limit only certain profiles can close case?
Easy... create validation rule with this formula, sample:
RecordType.Name = 'CSD Case' && ISCHANGED(IsClosed) 


Read this document for more information on Closing Cases.


Friday, November 29, 2013

Salesforce: Modify default View in Object Tab

By default, when user click an object tab in Salesforce, example: Account tab, user will be presented with latest View selected by login user, example in screenshot below, it show "My Accounts" view, this mean, user select "My Accounts" before open an Account or click anywhere else. After View is Recent Accounts list.

Note: list of accounts when user click this Account tab is NOT "My Accounts" view, but it is Recent Accounts, until user click Go! button next to View name or select another View.


But, can we modify the default view when user click the tab? 

YES, using Visualforce page. Don't be afraid, you not really need to understand the whole Visualforce page script and Apex code, just copy from script below :) 

1. Always show a View
You can start create visualforce page from Setup - Develop - Pages, click New button, enter the label and name, then copy and paste script below
<apex:page>
    <apex:enhancedList listId="00B500000063yvG" height="600" customizable="true" rowsPerPage="10"/>
</apex:page>

Explanation:
  • listId : the Salesforce object for which views are displayed. This value is required if type is not specified. From above example: you can grab this View Id from URL when open a View, sample: https://na3.salesforce.com/001?fcf=00B500000063yvG this is always 15 characters
  • height : an integer value that specifies the height of the list in pixels. This value is required.
  • customizable : a Boolean value that specifies whether the list can be customized by the current user. If not specified, the default value is true. If this attribute is set to false, the current user will not be able to edit the list definition or change the list name, filter criteria, columns displayed, column order, or visibility, however, the current user's personal preferences can still be set, such as column width or sort order. If this attribute is set to true, user will see Edit | Delete | Create New View links. 
  • rowsPerPage : an integer value that specifies the number of rows per page. Possible values are 10, 25, 50, 100, 200. Note: If you set the value for greater than 100, a message is automatically displayed to the user, warning of the potential for performance degradation.

2. Always show "Recently Viewed Objects"
<apex:page showHeader="true" tabstyle="Opportunity"> 
    <apex:ListViews type="Opportunity" /> 
</apex:page>




Okay, so we can customize the tab using simple Visualforce page, next question, how to put it on? Two option:

1. Overwrite existing standard tab
  • Setup - Account (for Account object) - Buttons, Links, and Actions
  • Look for Accounts Tab (just change the object name for other object)
  • Click Edit link 
  • Select Visualforce Page option then page you create above
  • Save
To note: once you overwrite the tab with visualforce, default Force.com Quick Access Menu at the middle right of the page of View page will be no longer available.

2. Create new tab
  • Setup - Create - Tabs
  • Go to Visualforce Tabs 
  • Click New button
  • Select Visualforce page you create above
  • Follow the wizard and Save

Loop back: how to modify columns in Recent Object view?

Reference: apex:enhancedList


Tuesday, November 26, 2013

Salesforce: Notes and Attachments

Notes and Attachments is not a new thing in Salesforce. I also do not see any enhancements in last few Salesforce release. But, for some users, Notes and Attachments still a nice feature and frequently used.

Here a few facts on Notes and Attachments good to remember:
  1. It is not possible to report on the Notes and Attachments related list.
  2. The Notes & Attachments can be exported directly via the API.
  3. It is possible to access your Notes & Attachments data by requesting a full data export of your organization's data. 
  4. The only way to get the attachment on a Salesforce email to Attachment is to download the attachment to your local machine, then manually added as an Attachment from the local machine location.
  5. Notes and attachments marked as Private via the Private checkbox are accessible only to the person who attached them, Administrators and users with View All Data permission.
  6. You must have “Read/Write” access to parent record to be able to add Notes or Attachments to the record.
  7. You also need to have “Read/Write” access permission to parent record to be able to edit or delete Notes or Attachments.
  8. You can write Apex trigger for Notes & Attachments using Force.IDE
Special thanks to Jason Lawrence for the input of Feed Attachment, so if you attach File to Chatter Feed in an Account or Opportunity, it will show as well in Notes & Attachments as Feed Attachment.



Have a nice day!

Salesforce: Freeze API

Six months back, I wrote this blog to disable user login to SFDC temporary, maybe for major internal release.

In Winter '14 release, Salesforce introduce Freeze user feature. Administrator can easily freeze user, so he/she will not able to login to Salesforce temporary. But, if you have 500 users to freeze, it is not a nice job to open each user and click Freeze button.

Luckily, Salesforce provide API for this. It is a field called IsFrozen, located in a new object, called UserLogin. You only can see this object using API version 29.0 and above, so if you use Data Loader, make sure it is version 29.0 and above. You can query and update this object, but not create and delete as it will sync to User object.

Screenshot from Data Loader














SOQL to this object using Developer Workbench
SELECT Id, IsFrozen, IsPasswordLocked, LastModifiedById, LastModifiedDate, UserId FROM UserLogin















Page-level ad