You need to sign in to do that
Don't have an account?
Dbjensen
Pass trigger.new and trigger.old to a single list
Hello - I'm trying to pass trigger.new and trigger.old to a single list which then will be passed to a class.
Here's the class I'm calling in the trigger:
LeadOwnerAssignment.assignOwner(Trigger.new, Trigger.old);
Here is the class method I'm passing the lists to:
public static void assignOwner(List<Lead> newLead, List<Lead> oldLead) {
I'm hoping to do something like this (except pass both trigger.new and trigger.old).
List<Lead> newLeadList = new List<Lead>();
for(Lead newLead : Trigger.new){
if(newLead.Lead_Id__c == null){
newLeadList .add(newLead);
}
}
LeadOwnerAssignment.assignOwner(newLeadList );
Any help would be greatly appreciated.
Here's the class I'm calling in the trigger:
LeadOwnerAssignment.assignOwner(Trigger.new, Trigger.old);
Here is the class method I'm passing the lists to:
public static void assignOwner(List<Lead> newLead, List<Lead> oldLead) {
I'm hoping to do something like this (except pass both trigger.new and trigger.old).
List<Lead> newLeadList = new List<Lead>();
for(Lead newLead : Trigger.new){
if(newLead.Lead_Id__c == null){
newLeadList .add(newLead);
}
}
LeadOwnerAssignment.assignOwner(newLeadList );
Any help would be greatly appreciated.
Yes, you can indeed pass your Trigger.New and Trigger.Old directly lists inside your class method. I would say you don't need to loop through the each record. Below as an example of an approach you may want to consider,
Trigger Code:
Handler Class with few methods:
Hope this helps!
If this resolves your query then please mark it as Best Answer!
Regards,
Harshil Parikh
All Answers
Yes, you can indeed pass your Trigger.New and Trigger.Old directly lists inside your class method. I would say you don't need to loop through the each record. Below as an example of an approach you may want to consider,
Trigger Code:
Handler Class with few methods:
Hope this helps!
If this resolves your query then please mark it as Best Answer!
Regards,
Harshil Parikh
Please read my comments here .. You can define a method to accept one list which contains both the old and new values .. its not a big deal .. but the problem here is how you will be able to identify which required is old and new .. to find the old and new in one list is challenge .
My opinion is you want to pass one Argument .. you can do it like that .. define the assignOwner method accept the Map<boolean,list<Account>>
LeadOwnerAssignment.assignOwner(new Map<Id,List<Account>>);
If the boolean value is true --> Consider the value as a new records
if the boolean value is false -- > consider the value as a old records