Calling a Remote Web URL from Salesforce
First, go to Setup | Security Controls | Remote Site Settings. Add the Plone sites you will need to call, such as:
http://web.npowerseattle.org/cps-development
Next, create an apex class that calls it:
global class UpdatePlone {
webservice static string UpdateDirectory(id conId) {
// plone url for directory updates
final string url = 'http://www.communitiesconnect.org/updateDirectoryEntry';
// notify plone that the account has changed
system.debug('Sending update request for: ' + conId);
system.debug('To URL: ' + url);
HttpRequest req = new HttpRequest();
req.setEndpoint(url + '?Id=' + conId);
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
return ('Salesforce sent this to Plone: ' + url + '?Id=' + acctId + ' ...and Plone said this: ' + res.toString());
}
static testMethod void TestAccountCreate() {
contact c = new contact(lastname='Test');
insert c;
UpdateDirectory(c.id);
}
}
Finally, create a contact button or link. Tell the button to run the following OnClick JavaScript:
{!REQUIRESCRIPT("/soap/ajax/11.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/11.0/apex.js")}
var result = sforce.apex.execute("Main","UpdateDirectory", {conId: "{!Contact.Id}"});
if (result.toString().indexOf("Status=OK")==-1) {
alert('Directory Update Failed! \n\n' + result);
} else {
alert('Directory entry was successfully updated.');
}
Add the button or link to the layout. Voila!
