-
How to show error message on the detail page of Salesforce sobject through before delete trigger?
I want to show error message on Account detail page, given below trigger shows error on the different page :-
trigger testDelete on Account (before delete)
{
List <Account> acc = [SELECT Id, (SELECT Id FROM Opportunities ) FROM Account WHERE Id IN : Trigger.old];
for(Account a : acc)
{
if(a.Opportunities.size()>0)
{
Trigger.oldmap.get(a.Id).addError('Cant Delete');
}
}
}
Log In to reply.
Popular Salesforce Blogs

Lightning Data Service (LDS) in Salesforce
If we have a lightning application that Creates, Reads, Updates or Deletes a record (basically CRUD operations) in the Salesforce database, Lightning Data Service (LDS)…

How to Show and Update External Data in Salesforce without consuming Salesforce Data Storage?
This is a common case when a customer wants you to integrate some system with Salesforce so that external data is displayed in Salesforce preferably…

Top Salesforce Spring '23 Revenue Cloud Features
Customers are prioritized by Revenue Cloud, allowing you to ensure outstanding customer experiences, streamline your revenue processes and data, automate the entire product-to-cash process to…