function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nununinununi 

Custom Delete button on standard layout

I am trying to create a custom delete button on an objectA which deletes the particular record only if the value in fieldA matches the Role of the logged in user. If it does not match it needs to throw an error. I was trying to use 'OnClick javascript". Can anyone help me wit the code? Thanks!
Best Answer chosen by nununi
vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
You can use the code below. Please mark it as best answer if it works for you.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}

var accountid = "{!Account.Id}"
var roleName = "{!$UserRole.Name}"
var accRole = "{!Account.RoleName__c}"
if(roleName == accRole)
{
var delResult = sforce.connection.deleteIds([accountid]);
if (delResult[0].getBoolean("success"))
{
  parent.location.href =('/001/o');
}
else {
sforce.debug.log("failed to delete account " + delResult[0]);
}
}
else
{
  alert('Doesnt match criterion');
}