Here I am pulling in data in bulk using the below statement
List<sumchans__MDU_Squad_Raw_Data__c> addressData = [SELECT sumchans__Street_Address__c,sumchans__City_Name__c,sumchans__Province_Code__c,sumchans__Postal_Code__c
FROM sumchans__MDU_Squad_Raw_Data__c WHERE sumchans__Street_Address__c IN :streetList AND sumchans__City_Name__c IN :cityList];
Using a for loop traversing through the addressData list above I am creating an addressMaster List below:
List<sumchans__Address_Master__c> addressMaster = new List<sumchans__Address_Master__c>();
for(sumchans__MDU_Squad_Raw_Data__c raw : addressData) {
String fullAddress = raw.sumchans__Street_Address__c+' '+raw.sumchans__City_Name__c+' '+raw.sumchans__Province_Code__c+' '+raw.sumchans__Postal_Code__c;
sumchans__Address_Master__c address = new sumchans__Address_Master__c();
address.Full_Address_Ext_Id__c = fullAddress;
}
addressMaster.add(address);
Now I am looping through the addressMaster list and adding the value of the Full_Address_Ext_Id field to a String List, for some reason I get an error saying variable does not exist. Not getting what I am doing wrong here. I have added everything to the addressMaster before accessing it below.
List<String> addresses = new List<String>();
for(String fullAddress: addressMaster) {
addresses.add(fullAddress.Full_Address_Ext_Id__c);// This statement says variable does not exist.
}
List <sumchans__Address_ColdCustomers__c> deletePrevColdCustomerList = [Select Id from sumchans__Address_ColdCustomers__c where Name in :addresses];
Delete deletePrevColdCustomerList;
EDIT after applying David Reeds answer
List<sumchans__Address_Master__c> addressMaster = new List<sumchans__Address_Master__c>();
for(sumchans__MDU_Squad_Raw_Data__c raw : addressData) {
String fullAddress = raw.sumchans__Street_Address__c+' '+raw.sumchans__City_Name__c+' '+raw.sumchans__Province_Code__c+' '+raw.sumchans__Postal_Code__c;
sumchans__Address_Master__c address = new sumchans__Address_Master__c();
address.sumchans__Full_Address_Ext_Id__c = fullAddress;
}
addressMaster.add(address);
Is this the way you mentioned:
List<sumchans__Address_Master__c> addresses = new List<sumchans__Address_Master__c>();
for(String fullAddress: addressMaster) {
addresses.add(fullAddress.sumchans__Full_Address_Ext_Id__c);
}
List <sumchans__Address_ColdCustomers__c> deletePrevColdCustomerList = [Select Id from sumchans__Address_ColdCustomers__c where Name in :addresses];
Delete deletePrevColdCustomerList;