You need to sign in to do that
Don't have an account?
anji punyamanthula
If I try to create Contact record without Account Id then it has to throw an error by using trigger hoe to do that
Below Example after taking Account als its throwing same error where i'm wrong let me know any one help in that
trigger con_accname_error on Contact (before insert,before update) {
for(contact c:trigger.new){
if(c.Account==null){
c.addError('pl enter account name');
}
}
}
trigger con_accname_error on Contact (before insert,before update) {
for(contact c:trigger.new){
if(c.Account==null){
c.addError('pl enter account name');
}
}
}
Please use the below code:
trigger con_accname_error on Contact (before insert,before update) {
for(contact c:trigger.new){
if(c.AccountId==null){
c.addError('pl enter account name');
}
}
}
Can you please Let me know if it works or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
All Answers
Please use the below code:
trigger con_accname_error on Contact (before insert,before update) {
for(contact c:trigger.new){
if(c.AccountId==null){
c.addError('pl enter account name');
}
}
}
Can you please Let me know if it works or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
addError method is provided by standard method, it dont mean that return the trigger. If you want to it do that you have to add return; after the addError.