You need to sign in to do that
Don't have an account?
Firas Taamallah 18
How can i use Apex parameter ?
I have this method
i want to remove Trigger.New and Trigger.Old and replace them with parameters like :
How can i declare OldRoles using the new parameter OldAccCont
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
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.
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)