Pretty new to development, so I'm probably missing something easy. From advice on this site, I'm trying to move my org's triggers into a trigger handler to be more manageable. I've started converting my triggers into classes, however when I try to call a method of one of these classes, I'm getting a Constructor not defined error.
Here is my constructor:
public class AddProductFromOfferingId {
Map<Id, Lead> newLeads;
public AddProductFromOfferingId(Map<Id, Lead> newTriggerLeads)
{
newLeads = newTriggerLeads;
}
}
And here's where I try to call the constructor:
public void beforeInsert(SObject so)
{
// Cast the SObject to an Lead
Lead theLead = (Lead)so;
if(theLead.Offering_ID__c != null)
{
AddProductFromOfferingId addProd = new AddProductFromOfferingId(Trigger.newMap);
}
The full error is: Constructor not defined: [AddProductFromOfferingId].<Constructor>(Map<Id, SOBject>)
.
In the constructor, I've named it AddProductFromOfferingId
, requiring one Id, Lead
map to be passed in. In my TriggerHandler class (second code snippet), I'm passing in a map. Can I not use Trigger.newMap in this way?
Update:
Thanks @BrianMansfield, your comment gave me what I needed. Adding the following to the handler class fixed my issue:
Map<Id, Lead> newMapFromTrigger = (Map<Id, Lead>) Trigger.newMap;