You need to sign in to do that
Don't have an account?
Hampton
Need Help With Batch Apex
Hello:
I have the following batch process written:
global class BatchToCreateAssignedAddress implements Database.Batchable<sObject>, Database.stateful { global string strqry=''; global BatchToCreateAssignedAddress(String q) { strqry=q; } global Database.Querylocator start (Database.Batchablecontext BC) { return Database.getQueryLocator(strqry); } global void execute (Database.Batchablecontext BC, list<sObject> scope) { Set<String> releaseName = new Set<String>(); for (Turf__c newDoor: [Select Name from Turf__c ]) { releaseName.add(newDoor.Name); } system.debug('*************releaseName :'+ releaseName); Map<String, Address__c> addressMap = new Map<String, Address__c>(); for(Address__c address1 : [Select ID, Name, Unparsed_Address__c, Release__c, Video_Qualification__c from Address__c where Release__c in : releaseName]){ addressMap.put(address1.Release__c, address1);} system.debug('*************addressMap size :'+ addressMap.size()); List<Assigned_Address__c> newAssignment = new List<Assigned_Address__c>(); for(Turf__c newRelease : [Select ID, Name, New_Resweep__c from Turf__c where Name = : releaseName] ) { system.debug('*************newRelease Name :'+ newRelease.Name); if(addressMap.containsKey(newRelease.Name)){ if(newRelease.New_Resweep__c == 'New'){ newAssignment.add(new Assigned_Address__c( Address__c = addressMap.get(newRelease.Name).Unparsed_Address__c, Turf__c = newRelease.ID, Address_ID__c = addressMap.get(newRelease.Name).ID)); system.debug('*************newAssignmentList Size :'+ newAssignment.size()); } } insert newAssignment; } } global void finish(Database.Batchablecontext BC) { } }
trigger NewAddressAssignment on Turf__c (after insert){ Set<String> releaseName = new Set<String>(); for (Turf__c newDoor: Trigger.new) { releaseName.add(newDoor.Name); string strquery= 'Select Id from Turf__c where ID in : releaseName'; BatchToCreateAssignedAddress objBatchToCreateAssignedAddress=new BatchToCreateAssignedAddress(strquery); Database.executeBatch(objBatchToCreateAssignedAddress); } }
According to my debug logs, in the trigger, the variable releaseName does not exist (Line 10). I have been trying to figure this out for hours and have had no luck.
The problem I am trying to solve for, is that when a new Turf__c record is created, there are child records (Assigned_Address__c) created as well. The number of child records created could be anywhere from 10 - 500.
Any help you can provide is much appreciated.
Thanks in advance!
Hampton
HI,
in this
Select Id from Turf__c where ID in : releaseName
release name is a string of newdoor.name not id
change two line
Set<id> releaseName = new Set<id>();
releaseName.add(newDoor.id);
AND