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 - Needs to delete only when Criteria is met

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
Dev.AshishDev.Ashish
Do something like this in your OnClick Javascript button.

if (ObjA.roleField == '{!$UserRole.Name}'){
            var url = '{!URLFOR($Action.ObjA.Delete, ObjA.Id, null, true)}'; 
            window.location.href = url;
            // allow user to delete 
        }
        else{
            alert('You do not have access to delete record');
        }