Sure, I can help you create a trigger to block delete if the record owner is not the logged-in user. To achieve this, you can use the "before delete" trigger event, where you have the opportunity to perform checks and validations before the records are actually deleted.
Here's an example of how you can implement this trigger in Apex:
trigger BlockDeleteOnOwnerCheck on YourObject__c (before delete) {
// Get the ID of the currently logged-in user
Id currentUserId = UserInfo.getUserId();
// Retrieve the records being deleted
List<YourObject_c> recordsToDelete = [SELECT Id, OwnerId FROM YourObject_c WHERE Id IN :Trigger.old];
// Iterate through the records and check if the owner is the current user
for (YourObject__c record : recordsToDelete) {
if (record.OwnerId != currentUserId) {
// If the owner is not the current user, add an error to block the deletion
record.addError('You cannot delete this record because you are not the owner.');
}
}
}
Sure, I can help you create a trigger to block delete if the record owner is not the logged-in user. To achieve this, you can use the "before delete" trigger event, where you have the opportunity to perform checks and validations before the records are actually deleted.
Here's an example of how you can implement this trigger in Apex:
Hope this helps !
Thank you.