You need to sign in to do that
Don't have an account?
MKPartners.com
Thanks in advance.
S-Control: Create Contact from Case submitted via Web
Has anyone created an S-Control that will take the information submitted via Web-to-Case and create a Contact and then relate the Case to that Contact?
This need must be common, so I'm hoping someone already has some code to leverage.
Thanks in advance.
-Matt
Matt,
I'm curious how you handled this. It is easy enough to use the AJAX toolkit to add code which will do this to the end of your webform, but in that case you have to have login details hard coded into the form... which isn't very secure unless you set up a special profile / user account just for this purpose.
Is that how you handled it?
-Michael
<html>
<head>
<title>Update Case</title>
<script src="/soap/ajax/13.0/connection.js" type="text/javascript"></script>
<script language="javascript">
function initPage()
{
window.setTimeout(createContactForCase, 200);
}
function createContactForCase()
{
try
{
if (parent.location.href.indexOf("_auto_create_contact_=1") > 0)
{
document.getElementById('_auto_create_contact_').innerHTML = "<center>contact populated</center>";
}
else if ('{!Case.ContactId}' != '')
{
document.getElementById('_auto_create_contact_').innerHTML = "<center>contact exists</center>";
}
else
{
var contactId = 0;
var emailString = "{!Case.SuppliedEmail}";
var result = sforce.connection.query("SELECT Id FROM Contact WHERE Email='" + emailString.replace(/'/g,"%27") + "'");
if (result && result.records && result.records.length > 0)
{
contactId = result.records[0].Id;
}
if (contactId == 0)
{
var newContact = new sforce.SObject("Contact");
newContact.set("Email", "{!Case.SuppliedEmail}");
newContact.set("FirstName", " ");
newContact.set("LastName", "{!Case.SuppliedName} ");
newContact.set("Phone", "{!Case.SuppliedPhone}");
var saveResult = sforce.connection.create([newContact])[0];
if (!saveResult || saveResult.success == 'false')
{
document.getElementById('_auto_create_contact_').innerHTML = "create contact error: " + saveResult;
return;
}
contactId = saveResult.id;
}
thisCase.set("Id","{!Case.Id}");
thisCase.set("ContactId", contactId);
saveResult = sforce.connection.update([thisCase])[0];
if (!saveResult || saveResult.success == 'false')
{
document.getElementById('_auto_create_contact_').innerHTML = "update case error: " + saveResult;
return;
}
//update ui and reload
document.getElementById('_auto_create_contact_').innerHTML = "<center>contact created, reloading...</center>";
window.setTimeout(reloadPage, 200);
}
}
catch (error)
{
document.getElementById('_auto_create_contact_').innerHTML = "unable to add contact - error: "+error; //.faultstring;
}
}
function reloadPage()
{
if (parent.location.href.indexOf("?") < 0)
parent.location.replace(parent.location.href + "?_auto_create_contact_=1");
else
parent.location.replace(parent.location.href + "&_auto_create_contact_=1");
}
</script>
</head>
</script>
</head>
<body onload="initPage();">
<div id='_auto_create_contact_'>
<center>
Updating contact ... <img src="/img/waiting_dots.gif" border="0" width=100 height=15>
</center>
</div>
</body>
</html>
Message Edited by --brooke-- on 08-12-2008 01:34 PM
Message Edited by --brooke-- on 08-20-2008 05:56 PM
Does any know whether this S-control will have governor Limit related problem?
I wrote a trigger to do the same as this S-control update case with contactId when
case.supplied email == Contact.email
Update case.contactid = contact.Id
But I am getting the following error
System.DmlException: Insert failed. First exception on row 0;
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
I want to use this S-Control,
Is there any limitation on how many cases it can process at a time?
Did any one see errors related to Governor limts using this S-control
I appreciate your comments/suggestions.
Thanks