[SalesForce] Create custom method in Apex batch class and make calls to it from execute method

I am trying to call a custom method called addColdCustomerToList from execute method, is that something that can be done inside a batch class.
global Database.QueryLocator start(Database.BatchableContext BC) {

}   

global void execute(Database.BatchableContext BC, List<sumchans__MDU_Squad_Raw_Data__c> rawData) {        

}

public void addColdCustomerToList(String fullAddress, String suiteNumber, String givenName, String surname,String telephoneNumber, String internetOffering, String videoOffering, String phoneOffering) {        
    sumchans__Address_ColdCustomers__c coldCustomer = new sumchans__Address_ColdCustomers__c(); // Tracking cold customers of this address.
    coldCustomer.Name = fullAddress;
}

global void finish(Database.BatchableContext BC) {

}

After the edits:
I am getting these 2 errors when saving this code

1. Method does not exist or incorrect signature: void addColdCustomerToList(String, String, String, String) from the type sumchans.MDUSquadAddressDataSummarizer

2. Invalid constructor name: addColdCustomerToList

    global Database.QueryLocator start(Database.BatchableContext BC) {
      return Database.getQueryLocator('SELECT sumchans__Street_Address__c,sumchans__City_Name__c FROM sumchans__MDU_Squad_Raw_Data__c');
}
global void execute(Database.BatchableContext BC, List<sumchans__MDU_Squad_Raw_Data__c> rawData) {        
     addColdCustomerToList(fullAddress,rawStats.sumchans__SUITE_NUM__c,rawStats.sumchans__GIVEN_NAME__c,rawStats.sumchans__SURNAME__c);           
}
public addColdCustomerToList(String fullAddress, String suiteNumber, String givenName, String surname) {        
     sumchans__Address_ColdCustomers__c coldCustomer = new sumchans__Address_ColdCustomers__c();
     coldCustomer.Name = fullAddress;
     coldCustomer.sumchans__ADDRESS_MASTER_EXT_ID__r = new sumchans__Address_Master__c(sumchans__Full_Address_Ext_Id__c = fullAddress);
     coldCustomer.sumchans__Suite_Number__c = suiteNumber;
     coldCustomer.sumchans__Full_Name__c = (((givenName).toLowerCase()).capitalize()) +' '+ (((surname).toLowerCase()).capitalize());
     addressColdCustomers.add(coldCustomer); 
}

Thank you all for the continued support.

Best Answer

You're missing a return type on addColdCustomerToList. Add void, for example.

Also, addressColdCustomers is undefined. You should give us complete code... it feels you're missing a lot here

Related Topic