My use case is to create a more specific error message when user tries to create a chattergroup(in the background by apex).
error message is for when user has reached the limit of 100 chattergroups he/she can join.Currently i am simply checking against error message to identify this.
Not sure whether its a good way to do this,because if sfdc changes message this doesnt work.is there any thing like an error code /or something more reliable to check this?
Code is below
How i am doing is in a before insert trigger(of a custom record), i do
try{
//create chatter groups
Database.Saveresult[] results = Database.insert(chatterGroups2Create, false);
for (Integer i = 0; i < results.size(); i++)
{
if (!results[i].isSuccess())
{
if ( results[i].getErrors()[0].getMessage() == 'Maximum per user collaboration group limit reached.')
{
newBets[i].addError('more specific error message');
}
else
{
newBets[i].addError(results[i].getErrors([0].getMessage());
}
}
else
{
//do something else
}
}
} catch (Exception e)
{
throw e;
}