You need to sign in to do that
Don't have an account?
djamouha
Testing addError return Validation Errors While Saving Record(s)
Hi guys,
I am having a trouble with the addError method. In fact I have done a litte code that block any user of our org from sending private message using Chatter. That looks like this :
This parts works pretty well as it returns on GUI the custom message and prevent sending the message.
The issue comes in the Test Class.
I am just doing something as simple as that :
But I always get this error when running the test : "Validation Errors While Saving Record(s)"
Any idea of where I am doing bad.
Regards
I am having a trouble with the addError method. In fact I have done a litte code that block any user of our org from sending private message using Chatter. That looks like this :
public static void insertNewChatterMessage(List<ChatterMessage> listeChatterMessages){ for(ChatterMessage c : listeChatterMessages){ System.debug('chat mess : '+c); c.Body.addError('Private Messages are not allowed'); } }
This parts works pretty well as it returns on GUI the custom message and prevent sending the message.
The issue comes in the Test Class.
I am just doing something as simple as that :
@isTest(SeeAllData=true) static void testChatterMessageBeforeInsert(){ Test.startTest(); try{ ConnectApi.ChatterMessages.sendMessage('Test chatter message', String.valueOf(userReceivingChatterMessage.Id)); throw new MyChatterException('Private Messages are not allowed'); } catch(DmlException e){ system.debug('###Mess : '+e.getMessage()); system.assert(e.getMessage().contains('Private Messages are not allowed')); } catch(MyChatterException f){ system.debug('###Mess : '+f.getMessage()); system.assert(!f.getMessage().contains('Private Messages are not allowed')); }
But I always get this error when running the test : "Validation Errors While Saving Record(s)"
Any idea of where I am doing bad.
Regards
The only error revealed by the test is what I mentionned : "Validation Errors While Saving Record(s)".
And in the debug log, I just see that when the trigger is called, I have this : "Internal Salesforce.com Error".
Here are the only informations I have about the error.