Realestate.com.au Leads to Salesforce via Email-to-Lead
Note: this is a pretty technical post so unless you "speak code", you may want to look at some of our other posts.
RealEstate.com.au is used by many of our property clients to generate enquiries for their projects. Those enquiries come through to our clients in the form of emails. We developed a solution so that those email-based enquiries can be automatically converted to Leads in Salesforce via an Email-to-Lead service.
The benefits of this approach include:
- No more missed enquiries: Emails can easily be missed with our ever-growing inboxes! By automatically creating Leads, our clients can't miss the enquiries - they'll see those open leads in Salesforce each time they log in.
- Saves time: Previously, our clients would have to manually copy and paste the details from the email into Salesforce - now it is automatically done for them.
- Improves your conversion rates: A study by Harvard Business Review showed that if you respond to a a lead within an hour, you are 7 times more likely to convert that lead to a sale. By streamlining the process of capturing the lead, and using workflow rules/triggers, along with the Salesforce One mobile app, you are much more likely to contact the enquirer within the all-important first hour.
Salesforce's Email Service
We will be using Salesforce's Email Service for this task:
Email services are special-purpose Force.com processes that use Apex classes to process incoming email messages.
This will create a dedicated Salesforce email address (e.g. firstname.lastname@example.org), and all emails to that address will be handled by an Apex class.
RealEstate.com.au require that you provide them a company email so we suggest asking your I.T department to set up a specific email address for all enquiries such as email@example.com. You will then forward on all emails received at that inbox to your Salesforce email service address.
The Email Service will need to be associated with an Apex class to handle the logic as per the notification:
An Apex class that functions as an inbound email handler should implement the Messaging.InboundEmailHandler interface, and a single method, handleInboundEmail. This method has 2 arguments: email, which you get the contents of the email from, and envelope, which stores the to and from addresses.
Normally, you would then use the following code to get the details of the enquirer from the email and store it in a Contact object:
However, with Realestate.com.au emails, the enquirer's details such as name and email address are embedded within the HTML-formatted email:
What we therefore have to do is break up the email into separate lines and then read the applicable lines to get the details we require. We also need to remove all of the HTML tags such as <strong> etc.
We will then know, for example, that the Name details is on line 37. We scan that line, and store the details in our Contact object:
The rest of the procedure is pretty much the same: find the relevant lines for the Email and the Project (so you associate a lead with a Project), and pull out the information.
We then create the Contact and provided there are no errors, we create a Lead with the ID that was returned from the Contact.
We can also put additional logic in there such as adding the Contact to a Campaign for that Project.
The above snippets only show a very small percentage of logic required to get this set up. However, our clients are very happy with result - less work for them and improved conversion rates!
It is by no means a perfect solution. If RealEstate.com.au change the layout of their email templates, we'll need to update our code accordingly or it will no longer function. RealEstate.com.au also have multiple templates depending on where the person enquired (e.g a Proejct page), so we need additional logic in there to determine the type of email sent.
If you would like assistance with setting up a similar service for your Salesforce environment, please email us at firstname.lastname@example.org for a free consultation.