Tuesday, 6 September 2016

Launch Outlook (or your default email client) From Salesforce Button


Sometimes your wants a functionality where they can launch their default email client (e.g. Outlook etc.) from a Salesforce button. The requirement can be further extended to pre-populate To, CC or BCC email addresses. Here is how to do it in both scenario i.e. static email adresses and dynamic email addresses:

STATIC EMAIL ADDRESSES: When you know whom you want to send email via outlook you can pre-populate To, CC and BCC email address. 

1. Create a custom button and make sure content source is URL


copy and paste the below string. You can modify the addresses, subject and body as per requirement.


mailto:client@salesforce.com?cc="cc@salesforce.com"&bcc="bcc@salesforce.com"&subject="This_is_my_subject"&body="Body_Text"

You can change the to, cc, bcc addressess as needed.


DYANAMIC EMAIL ADDRESSESS:

Lets say you want a button on account detail page which opens outlook will all contact email addresses pre-populated in BCC section of outlook. In such cases we need to create a javascript button. We will also need some apex/javascript logic to get all the contact email addresses. I am using Apex code but you can write your logic in javascript too.

1. Create a global APEX Class which has a method which returns colon separated email addresses of contacts. It should look like this:

global class AccountContactsEmailFetchService {


    webservice static String getContactEmails(String companyName){
       
        String subscriberEmails = '';
       
        //logic to create colon separated string of emails

  
        return subscriberEmails;
    }
}


2. Create a Javascript button (behaviour = execute javascript) and paste the following code:

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var companyNameParam = '{!Company__c.Name}';

var subscriberEmails = 
sforce.apex.execute("AccountContactsEmailFetchService ","getContactEmails",
{companyName: companyNameParam});

var urlStr = "mailto:client@salesforce.com?cc=cc@salesforce.com&bcc=";

urlStr = urlStr.concat(subscriberEmails);

urlStr = urlStr.concat("&subject=SUBJECT_GOES_HERE&body=Body_Text");

window.location.href = urlStr;


Save this button and add it to layout to see the magic. It will automatically open outlook with emails populate in bcc.

Let me know if you run into any issues. Leave a comment and I will try to respond ASAP

Thursday, 3 September 2015

Get Page URL in trigger !

In some use cases we need to know from which page the trigger is fired and design our business logic around it. In such cases we can use URL.getCurrentRequestUrl()  which returns the page URL from request is made (i.e. trigger is fired)

For example: We had a cleint requirement in where we need to change the name of document generated by a third party to a client specific format. It can be done using before insert trigger on attachments but then the renaming will also be done for the documents which user uploaded from standard Salesforce page. In this case, if we know that the request is coming from the standard salesforce attachment upload page - We can skip our trigger logic. There is a very simple way to do that.


You can use URL.getCurrentRequestUrl() in your trigger to get the URL from which the trigger is fired and then use it in our trigger logic. 

Wednesday, 12 February 2014

Auto Accept not working in Salesforce to Salesforce !!

You have set up a Salesforce to Salesforce connection with another org and started sharing records but you notice that the records are not getting auto accepted even if you have auto accept TURNED ON!

Well, here is the catch. Auto accept does not works if you have more than one look-up fields with the parent object. e.g. Cases will not be auto accepted if you create another custom look-up relationship with Contact, Contacts will not be auto-accepted if you create another custom look-up relationship with Account. This is mentioned in the documentation but many tend to forget this important condition.

The reason Salesforce.com implies this condition is obvious. If there are more than one lookups with parent object, the system would be confused in deciding which one to use to link with the parent object. Hence, it does not auto-accepts and asks to accept the record manually.

Monday, 18 February 2013

Allow users to share articles via public URLs

Every organization has a set of information, in Salesforce, this information is called Knowledge. A Knowledge base consists of various articles,article type, categories, sub categories etc. An article, as the name suggests, is a piece of information which we might want to share with the customer. 

Salesforce provides two methods of sharing articles with an external user via email.
1. Send article as attached PDF
2. Allow users to share articles via public URLs

Sending article as a PDF is quite straightforward. However, sending article URL is not that straightforward. In order to Send article as URL you first need to accomplish the following tasks.
1. A public Force.com Site dedicated to your articles.
2. A public knowledge base.

if you don't know how to set up a public knowledge base, you can implement it using salesforce guide :
https://ap1.salesforce.com/help/doc/en/salesforce_pkb_implementation_guide.pdf

After setting up public knowledge base make sure that the articles for which you want to share the URL are published and visible on public site.

Below are the steps:

STEP 1: Allow users to share articles via public URLs , you can do this by going to Your Name --> Setup --> Customize --> Knowledge --> Settings . Click the checkbox 'Allow users to share articles via public URLs'.

STEP 2: Enable Chatter feeds , you can do this by going to Your Name --> Setup --> Customize --> Cases --> Support Settings . Click the checkbox 'Case Feeds Enabled'. Also  make sure that your profile has sufficient permissions to view case feeds.

STEP  3: Attach the article you want to share with the case and click on 'Answer Customer' to send and Email. on the 'Articles' block below click down arrow button. You will get an option to 'Share article link from <Your Site Name> ' . On clicking this the URL for the article will be added to your Email. it looks something like this : 
Click the highlighted option and the URL will be added to Email.


Hope you find this helpful, if you face any problem don't hesitate to leave a comment or mail me.

Thursday, 14 February 2013

Display Cases in Home Page Layout or Home Tab

Many a times we need to display cases on the Home page layout or Home tab of user. We can customize our Homepage by using components provided by Salesforce like calendar,tasks,custom links but unfortunately, there is no standard component for Cases which we can include in our home page layout.

There is a solution. All we need to do is to create a simple visualforce page and include it in our layout. Here is the step by step solution

STEP 1- Turn on the development mode in your Salesforce org and create a simple visualforce page which displays a list of all the cases. Here is the code:

<apex:page showHeader="false">
<apex:ListViews type="Case" />
</apex:page>

STEP 2- Create a home page component using this visualforce. You can find the steps in this post

STEP 3- Select the layout and go to your home page. it will look something like this: 
Cases on Home Page Layout

However there is a crunch, if you click on a case it open it , it will be displayed like this.

No Body would like to  open a case like this right?

Obviuosly, this is not we want. Here a simple HTML tag comes to our help the <base> tag. We need to use the tag <base target="_parent"/> in our code. This will fix the error and will redirect us to the case record page whenever we click on a record. Thus the final step will be.

STEP 4 - Go to the visualforce page we created and edit the code. The new code of the visualforce page should be:

<apex:page showHeader="false">
<base target="_parent"/>
<apex:ListViews type="Case" />
</apex:page>

Click Save. Go to your home page you will get all the cases.

If you have any question or problem in impelementing it please leave a comment or mail me at shahid2889@gmail.com

I hope you will find this post useful.