I have a requierment where i need to update product values daily based on product extendent values. I created a batch apex as article extended values are more. I am getting but still gettin 10001 DML exception. Here is the execute code i
public class Article_Extendet_Values_batch implements database.batchable<sObject>, Database.AllowsCallouts, Database.Stateful { private String query; public Article_Extendet_Values_batch() { query = 'select Price__c, Article_Name__c, IdExt__c, Article__c,' +'Class__c, ExcludeFromLoyalty__c, LoyaltyPoints__c,LoyaltyRefundable__c,Type__c from Article_Extendet_Values__c'; //system.debug('query'+query); } public Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator(query); } public void execute(Database.BatchableContext BC, List <Article_Extendet_Values__c> scope) { // system.debug('articleid1scope'+scope); list<SCArticle__c> articleList = new list<SCArticle__c>(); set <id > artid= new set<id>(); for(Article_Extendet_Values__c art : scope) { artid.add(art.article__c); } list<ScArticle__c> mappedarticle=[select id,class__c,ExcludeFromLoyalty__c, LoyaltyPoints__c,LoyaltyRefundable__c,type__c,idext__c from ScArticle__c where id =:artid]; for( Article_Extendet_Values__c extval :scope){ for(SCArticle__C a : mappedarticle ){ a.Class__c = extVal.Class__c; a.ExcludeFromLoyalty__c = extVal.ExcludeFromLoyalty__c; a.LoyaltyPoints__c = extVal.LoyaltyPoints__c; a.LoyaltyRefundable__c = extVal.LoyaltyRefundable__c; a.Type__c = extVal.Type__c; a.IdExt__c = extVal.IdExt__c; // system.debug('class'+ a.Class__c); articleList.add(a); } } if(articleList.size() > 0) { try { update articleList ; } catch (DMLException e) { throw e; } } update articleList ; } public void finish(Database.BatchableContext BC) { } }
artidcould containnulland lead to this issue. Note also that it is not necessary to check for null before performing DML.