This trigger blocks users from saving Account updates if Ownership is set to “Private.” It includes validation logic to ensure data complies with business rules.
For further learning, explore this YouTube playlist.
Solution:
public class Account TriggerHandler {
public static void handleBeforeUpdateActivities (List<Account> newRecords, Map<Id,Account> oldMap) {
for (Account accRecord : newRecords) {
if (accRecord.Industry == ‘Agriculture’ && accRecord.Type == ‘Prospect’) {
//check if value of ownership was updated, and if it was updated, is the new value Private?
if (oldMap.get (accRecord.Id). Ownership != accRecord.Ownership &&
accRecord.Ownership == ‘Private’) {
accRecord.addError(‘Ownership cannot be modified’);
}
}
}
}
}