Friday, March 20, 2015

Salesforce: Merge Accounts - Simple Trick

Managing duplicate records is always a pain in any CRM. At times, when Duplicate Accounts are created in Salesforce, Salesforce has given an inbuilt feature to merge duplicate accounts. You will be able to find a link "Merge Accounts" on the standard account tab under Tools section.


People who have used this feature must have observed that User need to come back to Accounts Tab, then click the Merge Accounts link and manually enter the account name. But, all this can be done in one click. Here is the trick.

Create a custom button in Accounts
Setup > Customize > Accounts > Buttons, Links, and Actions > New Button
Enter following code in the body and Save.

/merge/accmergewizard.jsp?srch={!Account.Name}&retURL=%2F{!Account.Id}



Now add this button on your Account Page.



Once you have clicked the Account Merge button, It automatically puts the account name in the search box and displays the searched result for a Quick Action. :=)



Tuesday, May 20, 2014

Refreshing a Dashboard in Partner Community Portal

Salesforce has introduced dashboards in Partner Communities. However, Partner users do not have the ability to refresh any dashboard they have access to with the exception of the top row of any dashboard located on their Home page.  The List of “Report and Dashboard Limitations for Partner Community Users” can be found here. 

For a company who has a lot of Partner users, need the ability for these users to refresh a dynamic dashboard. Many customers implemented a solution to create individual dashboards for each partner, but dashboard doesn’t refresh automatically. A dashboard refresh is very critical as it is embarrassing to put a dashboard in front of partner users with data that is up to a month old. This defeats the purpose of them using dashboards and the Communities.

Bob Buzzard found a great solution to refresh a dashboard in Partner Communities. Here is the link to his solution “Automatic Dashboard Refresh”. Many thanks to Bob…

I have further worked on Bob’s clue and developed a simple solution similar to what Salesforce has offered to its standard users. I have used Simple XMLHttpRequest inside a Visualforce page to refresh a dashboard. This doesn’t require any controller, hence no need to write any test class. J


Step 1: Create a new Visualforce page with following code.
1:  <apex:page showHeader="false" sidebar="false" standardStylesheets="false">  
2:  <script type="text/javascript">  
3:  function refresh_win()  
4:  {  
5:       xmlhttp=new XMLHttpRequest();  
6:       xmlhttp.open("POST","https://{YourSiteName}.force.com/{YourPage}/dash/dashboardRefresh.apexp?id={YourDashboardID}",false);  
7:       xmlhttp.send();  
8:       alert('Refreshing Dashboard');  
9:       setTimeout('self.close();',2000);  
10:      setTimeout('parent.location.reload();',1000);  
11:  }  
12:  </script>  
13:  <form>  
14:  <input type="button" value="Refresh" onclick="refresh_win()"/>  
15:  </form>  
16:  </apex:page>  

Step 2: Adding this Visualforce page in a Dashboard

Go to Partner Dashboard. Click Edit. Add a new Visualforce component and this new Visualforce page. Set desired height and type relevant message. And you are Done…!



Friday, January 24, 2014

Salesforce.com: Send an Email to a list of Contacts Using Javascript

List view in Salesforce can help users accomplish activities in a faster way. You can do a Mass Edit / Update, Mass Transfer records from a list view. As of now, There is no out of the box functionality available to send an email to a list of contacts from Salesforce. (Mass mail is a completely different process. You need to create a separate list view and requires an email template)

Below mentioned code is a simple example in which Javascript is used to copy the email addresses of contacts selected from a list view and puts it into the "TO" box on a new email message.

This functionality can be handy when a user wants to send a simple mail to his contacts. You can optionally tag the activity to any object (Account, Opportunity, Case etc.)


For implementation:

Part I
Go to Setup > Customize > Contacts > Buttons, Links & Actions > New Button or Link
Choose Display Type as List Button & click Display Checkboxes (for Multi-Record Selection)
Behavior > "Execute JavaScript"
Content Source > "OnClick JavaScript"
Paste this code & Click Save

{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')} 
{!REQUIRESCRIPT('/soap/ajax/29.0/apex.js')} 
try{ 
var arrRecordId = {!GETRECORDIDS( $ObjectType.Contact)}; 
var ret = window.location.pathname+window.location.search; 
var pcEmail = arrRecordId[0]; 
if(arrRecordId.length > 0){ 
var strRecIdList = ''; 
for(var i=0; i < arrRecordId.length; i++){ 
strRecIdList += "'" + arrRecordId[i] + "',"; 

strRecIdList = strRecIdList.substring(0, strRecIdList.length-1); 
var contacts = sforce.connection.query("SELECT Email FROM Contact WHERE Id IN(" + strRecIdList + ")"); 
if(contacts.done == 'true' && parseInt(contacts.size)>0){ 
var cEmail = ''; 
for(var j=0; j < contacts.records.length; j++){ 
if(contacts.records[j].Email != null && contacts.records[j].Email != ''){ 
cEmail += contacts.records[j].Email + "; "; 


cEmail = (cEmail.substring(0, cEmail.length-1)).toString(); 
URL = '/_ui/core/email/author/EmailAuthor?p2_lkid='+pcEmail+'&p24='+cEmail+'&retURL='+ret; 
window.location.href= URL; 



catch(e){ 
alert('An Error has Occurred. \r\nError: ' + e); 
}


Part 2

Go to Setup > Customize > Contacts > Search Layouts
Click Edit next to Contacts List View
Add the new custom button and Save.

Now Click on Contacts Tab and then a list view to an send email.