You need to sign in to do that
Don't have an account?
Admin Part
Write a Trigger on Account Object, to prevent Deletion of an Account if Client_ID__c is not Null.
trigger accClient on account (before delete){
Set<ID> sId= new Set<sId>();
for(Account a: trigger.old)
{
sId.add(a.id);
}
Set<Account> as= [Select Id from Account
Where Client__c IN: sId];
for(Account a: trigger.old)
{
if(as.size > 0)
a.addError('cant Delete');
}
}
plz resolved
error: Error: Compile Error: unexpected token: '<' at line 7 column 5.
Set<ID> sId= new Set<sId>();
for(Account a: trigger.old)
{
sId.add(a.id);
}
Set<Account> as= [Select Id from Account
Where Client__c IN: sId];
for(Account a: trigger.old)
{
if(as.size > 0)
a.addError('cant Delete');
}
}
plz resolved
error: Error: Compile Error: unexpected token: '<' at line 7 column 5.
Set name cannot be reserved keyword. Since 'as' is an reserved keyword, try changing the set name and try to save again. It should work.
Try below trigger. I have tested it in my org and its working per requirements.
If this answer solves the query then please mark it best answered!
You can use the following trigger :
Apart from this in your code, you are getting a Compile Error in line 7 it’s because of
Wrong syntax “ if(as.size > 0) “ this can be replaced by “if(as.size() > 0)” .
There is also a logical error in your code that is your Code will display error on every account deletion because there is no check for clientId in the Code.
Hope this will help you. Mark this as best Answer if your problem solves.
Regards,
Ajay