Im new in capturing errors and showing errors within salesforce and....I am a bit lost....
I have a trigger that is fired when converting a lead into account. This trigger will update one field of the account.
The problem is that in our organization we only let the sales managers convert into exisiting accounts, not into new ones. But some of them still try to convert into new ones and then, because of the trigger they get this error:
Error: UpdateNumbercontactsWhenConverting: execution of AfterUpdate caused by: System.FinalException: SObject row does not allow errors Trigger.UpdateNumbercontactsWhenConverting: line 14, column 4
I would like to show them a different error, easier to understand, like: ERROR:you cannot convert a lead into a new account.
Any ideas on how to do it?This is my code. I tried with the addError but i get
Save error: Method does not exist or incorrect signature: addError(String)
I think my case is a bit special. I want to show the error in the conversion screen thats why when I use the statements you said they dont work. IUsing:
acc.addError('You cannot convert a lead into a new account only into an existing one');
I get the error:
Error: UpdateNumbercontactsWhenConverting: execution of AfterUpdate caused by: System.FinalException: SObject row does not allow errors Trigger.UpdateNumbercontactsWhenConverting: line 14, column 4
This conversion screen is some king of follow up....Maybe I cuold access to this follow up and show the error?
Hi,
Instead of that
addError('You cannot convert a lead into a new account only into an existing one');
Please use this to show error at top level
acc.addError('You cannot convert a lead into a new account only into an existing one');
Trigger.New[0].addError('You cannot convert a lead into a new account only into an existing one');
or to show error at field level
acc.Number_contacts__c.addError('You cannot convert a lead into a new account only into an existing one');
Hi,
Please refer following links.
http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with.html
http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with_29.html
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Chamil's Blog
Hi,
I think my case is a bit special. I want to show the error in the conversion screen thats why when I use the statements you said they dont work. IUsing:
acc.addError('You cannot convert a lead into a new account only into an existing one');
I get the error:
Thanks a lot!
please try
Trigger.New[0].addError('You cannot convert a lead into a new account only into an existing one');
Hi,
You cannot addErrors validation afterUpdate. You have to change it as beforeupdate.
trigger UpdateNumbercontactsWhenConverting onLead (beforeupdate) {
}
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Chamil's Blog
Now your trigger is on before update. You are checking
If(lead.IsConverted)
which will always return false, so addAccounts set will never be populated.
But I am checking the trigger.new what should contain the lead with the lead.isconverted = True, is that right?
How would you do it now to check that a lead is being converted?
Thanks