I’m getting better at writing javascript! I managed to hack together a onClick js button that did some Salesforce magic.

I had two disparate sources:

  • really old SF classic button code that would take the multi-selected records from a list view then perform field updates (change owner, populate driver fields, etc)
  • slightly more sophisticated code from Traction on Demand that from a single record would query for documents in the document pool associated to that lead, then send the found ID’s off for deletion

I was somehow able to nest them within? I guess? Rough code below



// set list to the ID's from the listview and init an empty array to hold the garbage
var list = SF.multiselectedRecords;
var idtodelete = [];

// for every ID in the list - run the query to find documents associated, returns JSON of request for each Lead
// you need to deconstruct that into an array of "records" to get the id's to delete
for (i in list) {
  var documentIDs = sf.query("SELECT docID FROM docs WHERE DocLocation = '" + list[i]"'")
  // for every returned document - extract the docID
  for (k in documentIDs) {
    push.documentIDs[k]
  }
}

Ok - so the site is built, what next?