global class oppbatch implements Database.Batchable { public String query; global oppbatch() { } global oppbatch(String str) { this.query = str; } global Database.QueryLocator start(Database.BatchableContext bc) { if(query == null || query == ''){ return Database.getQueryLocator([select id,SyncedQuoteId from Opportunity ]); }else{ return Database.getQueryLocator([select id,SyncedQuoteId from Opportunity where id =:query]); } } global void execute(Database.BatchableContext BC, list scope) { List targetList = new List(); List oppList = new List(); for(SObject s : scope){ Opportunity opp = (Opportunity) s; oppList.add(opp); targetList.add(opp.id); } List oliList = [select Id, ProductCode, ECCode__c, Quantity, OpportunityId, Opportunity.Amount from OpportunityLineItem where OpportunityId = :targetList order by OpportunityId, Id]; Map itemMap = new Map(); for (OpportunityLineItem oli : oliList) { if (itemMap.containsKey(oli.OpportunityId) == false) { itemMap.put(oli.OpportunityId, oli.ProductCode + '|' + oli.Quantity); } else { String tmp = itemMap.get(oli.OpportunityId); itemMap.put(oli.OpportunityId, tmp + ',\r\n' + oli.ProductCode + '|' + oli.Quantity); } } for (Opportunity newOpp : oppList) { //Opportunity oldOpp = oldMap.get(newOpp.Id); if (newOpp.SyncedQuoteId == null) { newOpp.OpportunityLineItemOT_text__c = itemMap.get(newOpp.Id); } } if(oppList.size() > 0){ update oppList; } } global void finish(Database.BatchableContext BC) { } public static void come(){ Integer i = 1; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; } }