0

I'm trying to deploy an apex trigger from sandbox to production. But when I test/validate in production I'm getting the error "variable does not exist" for the trigger's helper class:

Deployment Error Message

Trigger 'ZIPCodeAssignment:'

trigger ZIPCodeAssignment on Lead (before insert) {
if (Trigger.isBefore && Trigger.isInsert) {
    ZIPCodeAssignmentHelper.assignOwner(trigger.new);
}}

and the helper class 'ZIPCodeAssignmentHelper:'

public class ZIPCodeAssignmentHelper {
public static void assignOwner(List<Lead> leadList){
    Map<String,String> NameSalesRepMap = new Map<String,String>();
    List<String> zipcodes = new List<String>();
    Id recordTypeId = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Uniform and Linens').getRecordTypeId();


    for (Lead record : leadList) {
        if (record.PostalCode != null) {
            zipcodes.add(record.PostalCode);
        }
    }
    system.debug('zipcodes='+zipcodes);
    for(WUL_Sales_Territory__c codes :[SELECT WUL_Sales_Rep__c, Name FROM WUL_Sales_Territory__c WHERE Name IN :zipcodes]){
        NameSalesRepMap.put(codes.Name,codes.WUL_Sales_Rep__c);
    }
    system.debug('NameSalesRepMap='+NameSalesRepMap);
    if(!NameSalesRepMap.isEmpty()){
        for (Lead record : leadList) {
            if (record.PostalCode != null && record.RecordTypeId == recordTypeId) {
                if (NameSalesRepMap.containsKey(record.PostalCode)) {
                    record.OwnerId = NameSalesRepMap.get(record.PostalCode);
                }
            }
        }
    }
}}

Why is this happening? The helper class is listed as a dependency and the trigger fires properly in the sandbox as intended.

2
  • Can you manually add apex class in changeset? ZIPCodeAssignmentHelper Commented Jun 6, 2019 at 19:18
  • That was it @PranayJaiswal, didn't even think to add the helper class to the changeset. Duh. Thank you!
    – Ben Green
    Commented Jun 6, 2019 at 19:41

1 Answer 1

2

When we deploy any Trigger or Apex class you have to add all the components viz., Objects, ApexClass, etc., those are being referred in the Trigger/Apex class. Use View and Add Dependent Components to a Change Set in such scenarios to include all dependent components while deploying a particular component.

In this case, while deploying the Trigger, you will also need to deploy the referenced Handler referred by the Trigger.

2
  • 1
    +1. I took the liberty of adding few more details. Hope that works for you.
    – Jayant Das
    Commented Jun 6, 2019 at 19:56
  • 2
    Thanks Jayant, Much Appreciated. Commented Jun 6, 2019 at 19:59

You must log in to answer this question.

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