Skip to content

Instantly share code, notes, and snippets.

@arufian
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save arufian/197fc5ae7a1014fe61bb to your computer and use it in GitHub Desktop.

Select an option

Save arufian/197fc5ae7a1014fe61bb to your computer and use it in GitHub Desktop.

Revisions

  1. arufian revised this gist Jan 26, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // 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"));
    }
  2. arufian created this gist Jan 26, 2015.
    26 changes: 26 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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>