+ Start a Discussion
phil7sphil7s 

Automated Mail Merge

Greetings,
 
Has anyone seen any reference in Salesforce on how to automate a mail merge, or succesfully coded this?  For example, on creation of an object, I would like to automatically create a document containing record information.
 
I know I can code this on our back end through vb.net and then post that doc to SF as an attachment....just wondering what can be done in Salesforce either through the Web API, Workflow, etc.
 
Any help is appreciated!
 
Thanks,
Phillip
werewolfwerewolf
There's some mail merge functionality built into Salesforce.  Go to Help & Training and search for the article "Mail Merge Overview" to learn how to use it.  I believe it may do exactly what you need without any coding.
phil7sphil7s

do you have any specific links?  I've searched though SFDC (help training, wiki, ideas, discussions) the past couple of days and I havent found anything on "automated" mail merge......we currently do manual mail merges.

 

Thanks for the reply.

werewolfwerewolf
Ah, I see, you mean automated mail merge.  Sorry, I misunderstood the question.  Salesforce won't do that by default, mostly because it uses an ActiveX control to use the MS Word on your desktop to create the document.

Have you looked on the AppExchange at products like CongaMerge?  I think there are actually a few products already available which may do what you're looking for.
phil7sphil7s

yea I have, will probably look at them more in depth............i'm just a stickler for doing it myself if I can!

 

thanks for your feedback and info.

foghornfoghorn

If workflow can give you script control with the context of the record you want to use for the dataset, you can automate mail merge.

 

This is a snip from /mail/mmgen.jsp in the sfdc app:

 

                                var mainId  //main data id

                                var cid                  //primary contact. can be null

                                var did                  //templateid

 

                                var newMM = new ActiveXObject('AppExchangeMailMerge.MMHost.1')

 

                                var gackUrl                          = '/servlet/servlet.GackSender'

                                var gackList                         = 'gack@salesforce.com'

 

/*

Setup for standard date based merge that shows the unsaved results

*/

 

                                newMM.GenMailMerge(

                                                                                '433400D00000000hilP!AQsAQL7wRpF.BqG3w0wulRdf.nLctVZtdGoJGEOsJf.jhrtK9CaZXV3BkZjXB1.2GiTcoTcyaaNPgVLiHYjX9QoYY4oi4CUg',

                                                                                'https://ssl.salesforce.com',

                                                                                mainId,

                                                                                cid,

                                                                                did,

                                                                                gackUrl,

                                                                                gackList,

                                                                                false

                                                                                )

 

werewolfwerewolf
Foghorn,

I almost get that but not quite.  Is that some Javascript you've specified there which might run in the context of an Scontrol?
foghornfoghorn

Yup, this is javascript that will run in an scontrol (same script that runs when you click mail merge in the app, unless you are using serverside mailmerge?).

You need to supply:

a sid

id of "main" record to use for the merge

id of a contact to use (if you want)

id of the merge template

 

for the rest of the parms use the same values as the example.

 

btw, this script does not install the control, though you could do that if you need to.

 

bobby-ncbobby-nc

Hi, foghorn...  I need your help.

I am trying to use your code and receive a funky error I cannot debug - CMMHost::DownloadData:Exception...  Do you know what this means?

Code:
var newMM = new ActiveXObject("AppExchangeMailMerge.MMHost.1");
var mainId = strOpportunityId;    //main data id
var cid;      //primary contact. can be null
var did = "01H60000000EEYC";    //templateid
var gackUrl = "/servlet/servlet.GackSender";
var gackList = "gack@salesforce.com";

newMM.GenMailMerge(
 "433400D00000000hilP!AQsAQL7wRpF.BqG3w0wulRdf.nLctVZtdGoJGEOsJf.jhrtK9CaZXV3BkZjXB1.2GiTcoTcyaaNPgVLiHYjX9QoYY4oi4CUg",
 "https://ssl.salesforce.com",
 mainId,
 cid,
 did,
 gackUrl,
 gackList,
 false
 );


 

foghornfoghorn
Umm, what is the entire error message?
bobby-ncbobby-nc
Here it is:
 
Error:
CMMHost::DownloadData:Exception
An internal server error has occured while processing your request.
Url:https://ssl/salesforce.com/servlet/servlet.SForceMailMerge?
id=0060000009ttAg&did=01H60000000EEYC
Save to file name:C:\Documents and Settings\bobby\Application
Data\salesforce.com\OfficeToolkit\download\mergeData.xml
An internal server error has occured while processing your request.
Url:https://ssl.salesforce.com/servlet/servlet.GackSender?
recipient=gack@salesforce.com&subject=Mail%20merge%
20gack@body=cmm.host::DownloadData:Exception%0AAn%20internal%
20server%20error%20has%20occured%20while%20processing%20your%
20request.%0AUrl:https:%2F%2Fssl.salesforce.com%2Fservlet%
2Fservlet.SForceMailMerge?
id=00660000009ttAg&did=01H60000000EEYC
Save to file name:C:\Documents and Settings\bobby\Application
Data\salesforce.com\OfficeToolkit\download\mergeData.xml
%0AIE%20version:7.0.6000%AWord%20version:10.0.2627%
0AMSXML%20version:MSXML2.DOMDocument.4.0%0AVB%
20runtime%20versions:%0Amsvbvm50.dll:4.2.44%
0Amsvbvm60.dll:6.0.90
Save to file name:C:\Documents and Settings\bobby\Application
Data\salesforce.com\OfficeToolkit\download\mergeData.xml
Code: 0
lid=01N600000009BLX&ic=1
foghornfoghorn
Ah, you need to use your app server url, not ssl.salesforce.com
bobby-ncbobby-nc
Okay, I've tried https://na4.salesforce.com/ to no avail.  How do I determine the correct app server url for our org?  Or is there a way to call this dynamically?
foghornfoghorn
working example:
 
 


<html>

<head>

<script>

function go()
{
try
{

//login to get sid and serverurl

var sfApi = new ActiveXObject("SForceOfficeToolkit3.SForceSession3")
if(!sfApi.Login(un.value,pw.value))
{
alert(sfApi
.ErrorMessage)
return
}

var mainId = '00600000007m5Ki' //main data id
var cid = '' //primary contact. can be null
var did ='01H000000000CQQ' //templateid

var newMM = new ActiveXObject('AppExchangeMailMerge.MMHost.1')

var gackUrl = '/servlet/servlet.GackSender'
var gackList = 'gack@salesforce.com'

//get url to use, notice no trailing '/'

var i = sfApi.ServerUrl.indexOf('.com')
var serverUrl = sfApi.ServerUrl.substring(0,i + 4)

newMM
.GenMailMerge(
sfApi.SessionId,
serverUrl,
mainId,
cid,
did,
gackUrl,
gackList,
false
)
}
catch(exp)
{
alert(exp
.description)
}

}

</script>

</head>

<body>

username
<input type=text name=un ><br>
password
<input type=text name=pw ><br>

<input type=button onclick=go() value="Go">


</html>

bobby-ncbobby-nc
You are awesome...  Thank you very much!
Live agent integrationLive agent integration

Hi,

Your code is really helpful using that i have generated the mailm merge document.

My requirement is i need to capture that generated document and send it by Email as an atacment.

Can u plz help me on this?

Thanks in advance!!!!!!!

Rahul_sgRahul_sg
This should help :
http://boards.developerforce.com/t5/Visualforce-Development/render-VF-page-as-word-document/td-p/152538

Tip: You can save/email the vf page by writing code in your controller