Pages

Tuesday, August 30, 2016

Salesforce: Change Report Type

So, here is the use case: users need to change Report Type used for existing reports. But, can we change Report Type used by report?
Let's analyze, click "Customize" button and there is NO option to change the report type used for the report.


But, is there any workaround? Let's have a look with the report metadata.
 <?xml version="1.0" encoding="UTF-8"?>  
 <Report xmlns="http://soap.sforce.com/2006/04/metadata">  
   <columns>  
     <field>Account$Id</field>  
   </columns>  
   <columns>  
     <field>Account$Name</field>  
   </columns>  
   <columns>  
     <field>Account$Hello__c</field>  
   </columns>  
   <format>Tabular</format>  
   <name>Account with Hello</name>  
   <params>  
     <name>co</name>  
     <value>1</value>  
   </params>  
   <reportType>Account_Only_1__c</reportType>  
   <scope>organization</scope>  
   <showDetails>true</showDetails>  
   <timeFrameFilter>  
     <dateColumn>Account$CreatedDate</dateColumn>  
     <interval>INTERVAL_CUSTOM</interval>  
   </timeFrameFilter>  
 </Report>  
We found it and marked as bold above, is this mean we can just update it?

Next, let's see the Account_Only_1__c report type metadata:
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account Only with Hello</description>  
   <label>Account Only 1</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Country__c</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Hello__c</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>CreatedDate</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
 </ReportType>  

That's okay, now let's see the new report type that we would use as replacement, it is called "Account_Only_2__c"
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account Only without Hello</description>  
   <label>Account Only 2</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Country__c</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
 </ReportType>  

Next, go back to the report metadata and update <reportType> tag, from <reportType>Account_Only_1__c</reportType> to <reportType>Account_Only_2__c</reportType>

Save the metadata (in this case I am using MavensMate, the best IDE as David Liu said), hit Ctrl+S to save and will get following error:

The issue here because a custom field called Hello__c is not added to Account_Only_2__c report type, check that metadata above, so this is make sense.

Now, let's change it with other report type where Hello__c field is added, this report type called Account_Only_3__c.
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account Only with Hello</description>  
   <label>Account Only 3</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Hello__c</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>CreatedDate</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
 </ReportType>  
Back to the report metadata and update <reportType> tag, from <reportType>Account_Only_1__c</reportType> to <reportType>Account_Only_3__c</reportType>
Hit Ctrl+S to save the report, and we get Success message.


Now, back to the report in Salesforce and check again the report type by click Customize button, make sure to refresh the browser, not just click Customize or Run Report button when the report is already open.



Note: default report option availability such as: "Summarize information by" and  "Timeframe" is depend on the field defined in report type as well.


Conclusion: we can update Record Type used in Report by editing the report metadata, and the replacement report type should have all fields used in the report.



Sunday, August 28, 2016

Salesforce: Report Type Object Relationships


When you relate Object in Custom Report Type, you have option of:
  1. with or without related records (may or may not have related records)
  2. with at least one related records (must have at least one record)
The 1st option require at least one child record, otherwise the parent record will not show in the report generated, while the 2nd option do not require any child record. You can easily change the relation from 1st to 2nd, or 2nd to 1st anytime.

Let's look at the metadata for the different, it is just in a <outerJoin>

1. with or without related records
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account with Contacts only</description>  
   <join>  
     <outerJoin>false</outerJoin>  
     <relationship>Contacts</relationship>  
   </join>  
   <label>Account w/ Contacts</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>true</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>FirstName</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>LastName</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <masterLabel>Contacts</masterLabel>  
   </sections>  
 </ReportType>  

2. with at least one related records
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account with Contacts only</description>  
   <join>  
     <outerJoin>true</outerJoin>  
     <relationship>Contacts</relationship>  
   </join>  
   <label>Account w/ Contacts</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>true</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>FirstName</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>LastName</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <masterLabel>Contacts</masterLabel>  
   </sections>  
 </ReportType>  

Without Object Relationship
Now, let's take a look on simpler report type metadata which contain no object relationship - only Account for this sample, there is no <join> tag and no second <section> tag for related objects.
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account Only</description>  
   <label>Account Only</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>true</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
 </ReportType>  

Second Object Relationship
When the first object relationship is "must have at least one related", you have both the same option for second object relationship.


But, when the first object relationship is "may or may not have related record", you only have option "may or may not have related record" too for second object relationship.




Let's take a look on the metadata, we have additional <join> tag within <join> tag, and additional <section> tag.
 <?xml version="1.0" encoding="UTF-8"?>  
 <ReportType xmlns="http://soap.sforce.com/2006/04/metadata">  
   <baseObject>Account</baseObject>  
   <category>accounts</category>  
   <deployed>false</deployed>  
   <description>Account with Contacts with &amp; without Campaign History</description>  
   <join>  
     <join>  
       <outerJoin>true</outerJoin>  
       <relationship>CampaignMembers</relationship>  
     </join>  
     <outerJoin>false</outerJoin>  
     <relationship>Contacts</relationship>  
   </join>  
   <label>Account w/ Contacts w/ &amp; wo/ Campaign History</label>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Id</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Name</field>  
       <table>Account</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Owner.Department</field>  
       <table>Account</table>  
     </columns>  
     <masterLabel>Accounts</masterLabel>  
   </sections>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>FirstName</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>LastName</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Account</field>  
       <table>Account.Contacts</table>  
     </columns>  
     <masterLabel>Contacts</masterLabel>  
   </sections>  
   <sections>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Name</field>  
       <table>Account.Contacts.CampaignMembers</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>CampaignMemberRecordType</field>  
       <table>Account.Contacts.CampaignMembers</table>  
     </columns>  
     <columns>  
       <checkedByDefault>false</checkedByDefault>  
       <field>Status</field>  
       <table>Account.Contacts.CampaignMembers</table>  
     </columns>  
     <masterLabel>Campaign History</masterLabel>  
   </sections>  
 </ReportType>  




Friday, August 26, 2016

Salesforce: Enable Drag-and-Drop Scheduling on List Views

In earlier blog, we discussed about how to drag and drop to edit event from Calendar. Today we will share about feature to drag and drop scheduling on List Views.

This feature will let users create events associated with records by dragging records from list views to weekly calendar views and entering event details in an interactive overlay. The fields available in the event detail and edit overlays are defined in a mini page layout.

Admin need to enable this from Setup | User Interface | select Enable Drag-and-Drop Editing on Calendar Views | select Enable Click-and-Create Events on Calendar Views, then you can select Enable Drag-and-Drop Scheduling on List Views


This feature is only enable in Classic for Account, Contact, and Lead List View only, and Tab view is not count, meaning you need to select a View to see this.



1. Click the Open Calendar icon Open Calendar link at the bottom of a list view.
    A weekly view of a calendar appears below view.
 


2. Drag a record from the list to a time slot on the calendar.



3.  A popup window for creating an event appears. The event is already related to the record that you dragged from the list view.




Notes:
  • Drag-and-drop scheduling isn’t available for the Console tab, events that people have been invited to, recurring events, accessibility mode, or Connect Offline.
  • List views that include drag-and-drop scheduling can take slightly longer than usual to be displayed.
  • When you drag the bar in between the list and calendar to resize either one, the size is saved for all views in which you use drag-and-drop scheduling. You can resize the list and calendar at any time.


Reference:


Thursday, August 25, 2016

Salesforce: Enable Drag-and-Drop Editing on Calendar Views

In current era of Lightning; Classic still in the heart of many Salesforce users, and this blog is going to explain on how to use drag and drop in editing on Calendar Views, at this moment this feature only for Classic. Admin need to enable this from Setup | User Interface | select Enable Drag-and-Drop Editing on Calendar Views.

This feature will enable dragging of events on single-user, daily and weekly calendar views. This allows users to reschedule events without leaving the page



Once enabled, go to Calendar Day View or Week View (not Month View).



You should be able to drag and drop existing event for the week or day, this feature is not for Month View.



If you have Enable Click-and-Create Events on Calendar Views enabled, this will let users create events on day and week calendar views by double-clicking a specific time slot and entering event details in an interactive overlay. The fields available in the event detail and edit overlays are defined in a mini page layout. Recurring events and multi-person events aren’t supported for click-and-create events on calendar views.



Reference:


Sunday, August 21, 2016

Compilation of Salesforce Blogs with Alexa Rank

This compilation only for personal Salesforce blog with maximum Alexa rank not more than 11 millions.

You are active Salesforce blogger, but not see your name here...
You are Salesforce blogger, your name listed here, but some information is wrong...
You are Salesforce blogger, your name listed here, but you want to withdraw...

Comment below on this blog !

Thursday, August 18, 2016

Salesforce Migration Tool using ANT in Windows


Prerequisites

1. Java
Make sure JDK is installed in your computer.
Check it from Control Panel\All Control Panel Items\Programs and Features



** if you do not have JDK installed, download latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html

Once installed successfully, check from command prompt:
C:\>java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode, sharing)

** if your JAVA_HOME variable and environment Path have not configured, follow this step:
- Go to Advanced system settings from Control Panel\All Control Panel Items\System, click Environment Variables... button, go to System variables
- New variable JAVA_HOME value C:\Program Files\Java\jdk1.8.0_102 
- Edit Path variable to add value %JAVA_HOME%\bin


2. ANT
Get latest Apache ANT from http://ant.apache.org/bindownload.cgi and select .zip archive file.
Download the file to a folder and extract it.

You need to add this into System variables from Advanced system settings from Control Panel\All Control Panel Items\System, click Environment Variables... button.
- New variable ANT_HOME value C:\SFDC\Ant\apache-ant-1.9.7-bin\apache-ant-1.9.7
- Edit Path variable to add value %ANT_HOME%\bin

Once installed successfully, check from command prompt:
C:\>ant -version
Apache Ant(TM) version 1.9.7 compiled on April 9 2016


3. Force.com Migration Tool
Download Migration Tool from https://developer.salesforce.com/page/Force.com_Migration_Tool, at this moment it will bring me to https://gs0.salesforce.com/dwnld/SfdcAnt/salesforce_ant_37.0.zip, this may change based on Salesforce release. Extract salesforce_ant_37.0.zip to a folder.


Concept

You need to work with 3 files:

1. build.properties
Where? to store variables: username, password, server url
You can find sample of this file from "sample" folder from salesforce_ant_37.0.zip
In this file, you need define: serverurl, username, and password. Sample:
sf.serverurl = https://login.salesforce.com
sf.username = mylogin@gmail.com
sf.password = mypassword8

2. build.xml
How to deploy? retrieve, deploy
This file also available in "sample" folder from salesforce_ant_37.0.zip
In this file, you need to define the target. The concept here is you need to retrieve the metadata from source org., then deploy it to target org.

For retrieve
<target name="retrieve">  
  <!--<mkdir dir="retrieve_folder"/> -->
  <sf:retrieve username="${sf.username}" 
               password="${sf.password}" 
               sessionId="${sf.sessionId}"                 
               serverurl="${sf.serverurl}" 
               maxPoll="${sf.maxPoll}" 
               retrieveTarget="retrieve_folder" 
               unpackaged="package.xml" />
</target>

** mkdir retrieve_folder, this line is just needed if you need the script to create the folder prior retrieval, you can change retrieve_folder to other folder as you want.

For deployment
<target name="deploy"> 
  <sf:deploy username="${sf.username}" 
             password="${sf.password}" 
             sessionId="${sf.sessionId}" 
             serverurl="${sf.serverurl}" 
             maxPoll="${sf.maxPoll}" 
             deployRoot="retrieve_folder" 
             rollbackOnError="true"/>
</target>

** see more parameters here

3. package.xml
What to Deploy?
You can find sample of this file from "sample\codepkg" folder from salesforce_ant_37.0.zip
You need to manually add/update all the components you want to deploy.
Sample:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> 
  <types>        
    <members>Access_Account</members>
    <members>View_All_Data</members>
    <name>PermissionSet</name>
  </types>
  <types>
    <members>Change__c</members>
    <name>CustomObject</name>
  </types> 
  <types>
    <members>Sales Regional</members>
    <name>Profile</name>
  </types> 
  <version>37.0</version>
</Package>

For me personally, I prefer to create a folder and put all 3 files above into that folder for each deployment.

For complete Metadata Components and Types, see https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_objects_intro.htm


Action

This is exciting part where you will start using ANT

To retieve
C:\SFDC\Ant\salesforce_ant_37.0\sample>ant retrieve
Buildfile: C:\SFDC\Ant\salesforce_ant_37.0\sample\build.xml

retrieve:
[sf:retrieve] Request for a retrieve submitted successfully.
[sf:retrieve] Request ID for the current retrieve task: 09S17000001OuaREAS
[sf:retrieve] Waiting for server to finish processing the request...
[sf:retrieve] Request Status: Pending
[sf:retrieve] Request Status: Succeeded
[sf:retrieve] Finished request 09S17000001OuaREAS successfully.

BUILD SUCCESSFUL
Total time: 28 seconds

To deploy
C:\SFDC\Ant\salesforce_ant_37.0\sample>ant deploy
Buildfile: C:\SFDC\Ant\salesforce_ant_37.0\sample\build.xml

deploy:
[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request ID for the current deploy task: 0Af21000002F9xACAS
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: Pending
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: Succeeded
[sf:deploy] *********** DEPLOYMENT SUCCEEDED ***********
[sf:deploy] Finished request 0Af21000002F9xACAS successfully.

BUILD SUCCESSFUL
Total time: 30 seconds



Reference:


Page-level ad