Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Created January 25, 2015 17:37
Show Gist options
  • Save Sunil02kumar/a36b7a8078a58049d18c to your computer and use it in GitHub Desktop.
Save Sunil02kumar/a36b7a8078a58049d18c to your computer and use it in GitHub Desktop.
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
try{
var caseId = '{!Case.id}';
if(confirm('Are you sure you want to assign this case to yourself.')) {
//fetch logged in User details
var user = sforce.connection.getUserInfo();
var CaseToUpdate = [];
var rec =sforce.connection.query("Select id,ownerId from Case where id='"+caseId+"' Limit 1");
var records = rec.getArray("records");
if(records.length) {
for(var j=0;j<records.length;j++){
var cas = new sforce.SObject("Case");
cas.Id=records[j].Id;
cas.ownerId=user.userId;
//here modify any field value
CaseToUpdate.push(cas);
}
result = sforce.connection.update(CaseToUpdate);
if (result[0].success == 'true'){
alert('Case assigned successfully');
window.location.href = '/'+caseId;
}else{
alert('An error has occoured. Error: '+result[0].errors.message);
window.location.href = '/'+caseId ;
}
}
}
}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