Created
January 25, 2015 17:37
-
-
Save Sunil02kumar/a36b7a8078a58049d18c 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 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