You need to sign in to do that
Don't have an account?
Kaity
Is this Trigger Bulkified?
Hi,
Is this trigger is bulkified? I have taken this trigger from one blogg???? Here, we have not use any list or set....
trigger preventDeletion On Account(before delete){
for(Contact c :[SELECT Id, AccountId From Contact where AccountId In: Trigger.oldmap.keyset() ]){
Trigger.oldMap.get(c.AccountId).addError('Cannot delete Account with a Contact');
}
}
Yes this code is bulkified and bulk safe
Since you are concerned about using set I am just adding some comments for you
All Answers
Yes this code is bulkified and bulk safe
Since you are concerned about using set I am just adding some comments for you
I hit kudos , not because you answered me but because you show true mentorship and your strength in APEX. Superb explanation.
Need and expect much more such guidance. Thank you.
-Kaity
Hi Avi,
The code is functionally working fine, but from UI, it looks very odd/ugly. Can't we bring the error message in Detail page of Account(like in VF page) ??
Detail Page ? Are you looking something like "Page Messages" ?
Well probably not.
But you can send in your own html from the backend.
There are 2 questions:
How to make the error comment to show in red font.
Why did we use False?? (Is it act like return type???)
First one is good:
Trigger.oldMap.get(c.AccountId).addError('<b><font color="red"/><font>Cannot delete Account with a Contact</b>', false);
Donot know the second query??
Well the false is to specify whether to escape the html tags or not. If you specify the second param as false, html wont be escaped and browser will actually render the HTML content.
So if you are adding some html tags in your error message and want the same to render, you have to switch this flag to false.