0

I can't figure out why this code will not update all three records from the SOQL statement. There is only 1 record updated and the two records are ignored.

In Developer Console:

List<Business__c> defaultList = [Select Id, Name, Business_Name__c, Status__c From Business__c];
system.debug(defaultList.size());//This shows there are 3 records
Business__c[] defaultUpdate = New Business__c[]{};
for (Business__c d : defaultList){           
    //Default Values
    defaultUpdate.add(New Business__c(ID = d.ID, Update_Name__c = d.Business_Name__c, Update_Status__c = d.Status__c));          
}
database.Update(defaultUpdate, false);

1 Answer 1

1

Whenever you use Database.update, you need to check the results of the DML as no exception will be thrown if an error (like a validation rule error)

Database.SaveResult[] srList = Database.update(defaultUpdate,false); // allow partial succcesses
for (Integer i = 0; i < srList.size(); i++)
  if (!srList[i].isSuccess()) 
   // do something - look at getErrors(). 

If you used:

 update defaultUpdate;

then any errors in the update will be thrown as an exception unless you wrap (as you should) the DML with a try-catch block

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .