title: Salesforce - Executing Javascript through Apex Controller
body: <p>Im new to Salesforce in general and Im trying to decide how to handle the invoking of a SOAP webservice. Currently the webservice is being executed via AJAX when a user clicks a button on the Opportunity page. I have been asked to move the webservice invocation from the button and place it into a custom controller page. So the webservice needs to be invoked seamlessly when certain conditions are met, opposed to having the user click a button.</p>
  
  <p>I'd like to just kick off the webservice using the same ajax statement because it will save me time. Although it would seem to make more sense to invoke the webservice via Apex, but am still researching that topic. So here is my question:</p>
  
  <p>Is it possible to execute the following javascript from within an Apex controller? If so how?</p>
  
  <pre><code>{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
  {!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
  var xfolder = "MyNewFolder"
  var parentid = "999999999999999"
  var myvar = sforce.apex.execute("myWS","invokeExternalWs", {folderName:xfolder,ObjectID:parentid});
  window.alert('Folder created: ' + myvar);
  </code></pre>