0

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;

1 Answer 1

1

There's likely two problems here.

for(String fullAddress: addressMaster) {

addressMaster is typed as a List<sumchans__Address_Master__c>, not a List<String>, so your loop variable is the wrong type.

But also, you're referring to this field without a namespace prefix in two places:

      address.Full_Address_Ext_Id__c = fullAddress;
addresses.add(fullAddress.Full_Address_Ext_Id__c);

If that field is part of the managed package, as opposed to an unpackaged custom field, you need the sumchans__ prefix.

5
  • Thanks @David, I just added an edit to the below of my original post, still I get the same error plus it says invaid bind of expression type of sumchans__Address_Master__c for column of type string.
    – sumchans
    Commented Apr 17, 2020 at 22:27
  • Could you please check. thanks again.
    – sumchans
    Commented Apr 17, 2020 at 22:27
  • I don't really understand what you're trying to do. You're copying data back and forth between Strings and records of this custom object, which is fine, but you have to be consistent about which value is of which type.
    – David Reed
    Commented Apr 17, 2020 at 22:32
  • addresses is a List<sumchans__Address_Master__c>. It looks like you probably meant it to be a List<String>.
    – David Reed
    Commented Apr 17, 2020 at 22:33
  • Okay got it now, the error is gone.
    – sumchans
    Commented Apr 17, 2020 at 22:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .