function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Firas Taamallah 18Firas Taamallah 18 

How can i use Apex parameter ?

I have this method
 
Public void Method(){
for (AccountContactRelation accountContactRelation : (List<AccountContactRelation>) Trigger.new) {
            String oldRoles = (Trigger.isUpdate) ? ((AccountContactRelation) Trigger.oldMap.get(accountContactRelation.Id)).Roles : null;

            if (accountContactRelation.Roles != null && accountContactRelation.Roles.contains(Label1) && (Trigger.isInsert ||
                    (Trigger.isUpdate && (oldRoles == null || !oldRoles.contains(Label1))))) {
                if (!accountContactRelationIdsMap.containsKey(accountContactRelation.AccountId)) {
                    accountContactRelationIdsMap.put(accountContactRelation.AccountId, new List<Id>());
                }
                accountContactRelationIdsMap.get(accountContactRelation.AccountId).add(accountContactRelation.ContactId);
            }
        }

i want to remove Trigger.New and Trigger.Old and replace them with parameters like : 
 
Public void Method(List<AccountContactRelation> NewAccCont , List<AccountContactRelation> OldAccCont){

for (AccountContactRelation accountContactRelation : NewAccCont ) {

//How can i declare OldRoles using the parameter OldAccCont

            String oldRoles = (Trigger.isUpdate) ? ((AccountContactRelation) Trigger.oldMap.get(accountContactRelation.Id)).Roles : null;

            if (accountContactRelation.Roles != null && accountContactRelation.Roles.contains(Label1) && (Trigger.isInsert ||
                    (Trigger.isUpdate && (oldRoles == null || !oldRoles.contains(Label1))))) {
                if (!accountContactRelationIdsMap.containsKey(accountContactRelation.AccountId)) {
                    accountContactRelationIdsMap.put(accountContactRelation.AccountId, new List<Id>());
                }
                accountContactRelationIdsMap.get(accountContactRelation.AccountId).add(accountContactRelation.ContactId);
            }
        }

How can i declare OldRoles using the new parameter OldAccCont
RituSharmaRituSharma
Instead of doing like below:
String oldRoles = (Trigger.isUpdate) ? ((AccountContactRelation) Trigger.oldMap.get(accountContactRelation.Id)).Roles : null;

You may check OldAccCont list. If list is not null then it's update scenario else it's insert scenario.
ABravo473ABravo473
You can just pass the new list and old list to your apex method from the trigger. Trigger.New and Trigger.Old will give you the list of records where as Trigger.NewMap and Trigger.oldMap will give you Map.
lets consider the trigger as AccountTrigger and class as AccountTriggerHandler.
AccountTrigger :
     AccountTriggerHandler ach = new AccountTriggerHandler();
     ach.Method(trigger.New, trigger.Old);

AccountTriggerHandler :
     Method(List<AccountContactRelation> NewAccCont , List<AccountContactRelation> OldAccCont)
Firas Taamallah 18Firas Taamallah 18
Well , that method is in batch class .. i couldn't execute the batch from apex class
Millar DakkimMillar Dakkim
There is little bit wrongYou need to find quality and responsible and good developers. So here you can use my recommendation "how to find good team" is a light-it.net (https://light-it.net/) developer because any tech project needs professional experts and a dev team.