Last active
August 29, 2015 14:14
-
-
Save arufian/197fc5ae7a1014fe61bb to your computer and use it in GitHub Desktop.
Yet Another Salesforce REST API with JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// refs: http://www.jitendrazaa.com/blog/salesforce/salesforce-rest-api-playground/ | |
function getQueryStringValue (key) { | |
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); | |
} | |
{!REQUIRESCRIPT ("/soap/ajax/13.0/connection.js")}; | |
var records = {!GETRECORDIDS($ObjectType.Book__c)}; | |
var counter = 0; | |
for(var i=0; i<records.length; i++){ | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp .onload = function(e) { | |
counter++; | |
if(counter === records.length) { | |
var fcf = getQueryStringValue('fcf'); | |
var winlocation = window.location; | |
window.open(winlocation.pathname + '/x?fcf='+fcf); | |
} | |
} | |
xmlhttp.open("PATCH", '/services/data/v29.0/sobjects/Book__c/'+records[i], true); | |
xmlhttp.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); | |
xmlhttp.setRequestHeader('Authorization', 'Bearer {!$Api.Session_ID}'); | |
xmlhttp.send(JSON.stringify({IsPrinted__c:"true"})); | |
} | |
</script> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment