Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Database Salesforce Apps & Add-ons Calling a Remote Web URL from Salesforce

Calling a Remote Web URL from Salesforce

An example of calling a remote url (in this case a Plone script) 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!

Document Actions

Comments (0)

« February 2012 »
February
MoTuWeThFrSaSu
12345
6789101112
13141516171819
20212223242526
272829