I have this piece of code,where i am trying to insert a record(which throws me duplicate issue).But i am trying to insert it using database.insert

EntitySubscription e = [select id from EntitySubscription where ParentId = 'a0CM0000005hyYAMAY' and SubscriberId= '005M0000005BqhVIAS'];
//e exists
EntitySubscription a = new EntitySubscription(ParentId = 'a0CM0000005hyYAMAY',SubscriberId= '005M0000005BqhVIAS');
List<EntitySubscription> collaborationBetMembers = new List<EntitySubscription>();
Database.Saveresult[] saveResult; 
saveResult = Database.insert(collaborationBetMembers);

Now my issue is above code throws an exception but when i specify false parameter explicityly in

saveResult = Database.insert(collaborationBetMembers,false);

It doesnt throw exception. which is confusing because this documentation shows,its false my default..so my assumption is you dont need to write it explicitly.any idea why http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_methods_system_database_saveresult.htm|StartTopic=Content%2Fapex_methods_system_database_saveresult.htm|SkinName=webhelp

Exception i get is below

System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: duplicates value on record with id: : []:
  • what exception are you getting?
    – Bforce
    Feb 4, 2014 at 12:05
  • i updated above with exception :)
    – sfdc99999
    Feb 4, 2014 at 12:08
  • Database.insert should always take 2 parameters as per this link salesforce.com/us/developer/docs/apexcode/Content/… . I cant find the method that takes only one parameter. Nor can i find anything specifying any default value.
    – AslamK
    Feb 4, 2014 at 12:27
  • No where in document says the parameter is false by default Feb 4, 2014 at 12:30
  • I agree with above, the only thin I could find on default values for AllOrNone is here salesforce.com/us/developer/docs/api/Content/…. This is for the API though and I don't think applies here. You have to set both parameters for the method. Feb 4, 2014 at 12:37

1 Answer 1


This code does throw exception. It is just handled and saved in SaveResult Object. Quite similarly like try{} Catch(exception ex){} - here it also does throw exception but don't break session because you handle it.

Solution for you is to create method that will check SaveResult and look for error.

for(Database.SaveResult sr : saveResult){            
    if (!sr.isSuccess()) {
        /** Some tasks if Error found **/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.