+ Start a Discussion

Need Help With Batch Apex



I have the following batch process written:


global class BatchToCreateAssignedAddress implements Database.Batchable<sObject>, Database.stateful
global string strqry='';
global BatchToCreateAssignedAddress(String 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(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) {

string strquery= 'Select Id from Turf__c where ID in : releaseName';

BatchToCreateAssignedAddress objBatchToCreateAssignedAddress=new BatchToCreateAssignedAddress(strquery);

 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!



sushant sussushant sus

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>();



for (Turf__c newDoor: [Select Name from Turf__c ])

can use

  for (Turf__c newDoor: scope)