Created
January 25, 2015 17:41
-
-
Save Sunil02kumar/b552e1b9351956864522 to your computer and use it in GitHub Desktop.
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
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} | |
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} | |
try{ | |
var records = {!GETRECORDIDS($ObjectType.Contact)}; | |
var SelectedIds=''; | |
var updatedList = []; //list of contacts to be updated | |
var accid; | |
if(records.length<1) { | |
alert("Please choose at least one contact."); | |
}else { | |
for(var i=0;i < records.length; i++){ | |
SelectedIds+="'"+records[i]+"',"; | |
} | |
SelectedIds=SelectedIds.substring(0,SelectedIds.length - 1); | |
alert(SelectedIds); | |
var project = sforce.connection.query("Select id, Name,AccountId,contact_update_required__c from Contact where id in ("+SelectedIds+")"); | |
var cons1 = project.getArray("records"); | |
if(cons1.length){ | |
for (var n=0; n<cons1.length; n++){ | |
var sf = new sforce.SObject("Contact"); | |
sf.id = cons1[n].Id; | |
sf.contact_update_required__c=true; | |
accid=cons1[n].AccountId; | |
updatedList.push(sf); | |
} | |
var result = sforce.connection.update(updatedList); | |
if (result[0].success == 'true'){ | |
alert('Records updated successfully'); | |
window.location.href = '/'+accid; | |
}else{ | |
alert('An error has occoured. Error: '+result[0].errors.message); | |
window.location.href = '/'+accid ; | |
} | |
} | |
} | |
}catch(e){ | |
alert('some system error occured. Please try later'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment