Wednesday, August 26, 2015

Salesforce Sortable Changeset Dependency List

Sorting the results of 'View/Add Dependencies'

When you have to shift through over 100+ entries it would help if SF's interface allowed for sorting. The missing functionality can be achieved by running the below JS, which can be invoked using a handy bookmarklet. Create one as follows:
  • In your browser add a new bookmark
  • Name it `SF Make `<table class='list' ...>` Sortable`
  • In the url paste the blelow JS snippet
javascript:/* `sortTable` from https://gist.github.com/danielsokolowski/994d47baa95ef81fd8fc */ function TableSort(a){this.tbl=a;this.lastSortedTh=null;if(this.tbl&&"TABLE"==this.tbl.nodeName){a=this.tbl.tHead.rows[0].cells;for(var b=0;a[b];b++)a[b].className.match(/asc|dsc/)&&(this.lastSortedTh=a[b]);this.makeSortable()}}TableSort.prototype.makeSortable=function(){for(var a=this.tbl.tHead.rows[0].cells,b=0;a[b];b++){a[b].cIdx=b;var c=document.createElement("a");c.href="#";c.innerHTML=a[b].innerHTML;c.onclick=function(a){return function(){a.sortCol(this);return!1}}(this);a[b].innerHTML="";a[b].appendChild(c)}};TableSort.prototype.sortCol=function(a){var b=this.tbl.rows,c=[],f=[],g=0,d=0;a=a.parentNode;for(var l=a.cIdx,e=1;b[e];e++){var h=b[e].cells[l],h=h.textContent?h.textContent:h.innerText,k=h.replace(/(\$|\,|\s)/g,"");parseFloat(k)==k?f[d++]={value:Number(k),row:b[e]}:c[g++]={value:h,row:b[e]}}b=[];a.className.match("asc")?(e=bubbleSort(c,-1),c=bubbleSort(f,-1),a.className=a.className.replace(/asc/,"dsc")):(e=bubbleSort(f,1),c=bubbleSort(c,1),a.className.match("dsc")?a.className=a.className.replace(/dsc/,"asc"):a.className+="asc");this.lastSortedTh&&a!=this.lastSortedTh&&(this.lastSortedTh.className=this.lastSortedTh.className.replace(/dsc|asc/g,""));this.lastSortedTh=a;b=e.concat(c);c=this.tbl.tBodies[0];for(e=0;b[e];e++)c.appendChild(b[e].row)};function bubbleSort(a,b){var c,f;1===b?(c=0,f=a.length):-1===b&&(c=a.length-1,f=-1);for(var g=!0;g;)for(var g=!1,d=c;d!=f;d+=b)a[d+b]&&a[d].value>a[d+b].value&&(g=a[d],a[d]=a[d+b],a[d+b]=g,g=!0);return a};new TableSort(document.querySelector('table.list'));

Example of sorting the Salesforce Chageset dependency list


If you found this post useful, please post a comment or follow me on twitter .

No comments:

Post a Comment