You need to sign in to do that
Don't have an account?
fiona gentry
How to resolve Trigger handler error void add(Object) from the type Set<Id>
Hi folks,
How to resolve the this error in the logic of the trigger handler class
Here is trigger apex
Regards
Fiona
How to resolve the this error in the logic of the trigger handler class
Method does not exist or incorrect signature: void add(Object) from the type Set<Id>
Here is trigger apex
trigger TaskTrigger on Task (before insert) { if(Trigger.isBefore&&Trigger.isInsert){ TaskTriggerHandler.beforeInsert(Trigger.New); } Map<Id, Task> mapTaskWithRelatedTask = new Map<Id, Task>(); Set<Id> setWhatIds = new Set<Id>(); for (Task objTask : Trigger.New) { mapTaskWithRelatedTask.put(objTask.whatId, objTask); } for (AggregateResult ar : [SELECT whatId FROM Task WHERE whatId IN: mapTaskWithRelatedTask.keySet() AND Action__c = 'Airtel contact' GROUP BY whatId]) { setWhatIds.add(ar.get('whatId')); } for (Task objTask : mapTaskWithRelatedTask.values()) { if (!setWhatIds.contains(objTask.whatId)) { objTask.addError('Please Create a task for airtel account contact Research before creating any other Task'); } } }Your help is appreciated
Regards
Fiona
try with below code.
If this helps, Please mark it as best answer.
thanks!!
Map<Id, Task> mapTaskWithRelatedTask = new Map<Id, Task>();
Set<Id> setWhatIds = new Set<Id>();
you have created above map , and set in which you are adding whatId of tasks.
setWhatIds.add(ar.get('whatId')); In these line you getting Id which return you the task object itself. So thats the reason of error void add(Object) from the type Set<Id>
Solution :
Map<Task, Id> mapTaskWithRelatedTask = new Map<Task, Id>();
If(trigger.Isbefore && Trigger.Isinsert){
for (Task objTask : Trigger.New) {
mapTaskWithRelatedTask.put( objTask,objTask.whatId);
}
}
for (AggregateResult ar : [SELECT whatId FROM Task WHERE whatId IN: mapTaskWithRelatedTask.values() AND Action__c = 'Airtel contact' GROUP BY whatId]) {
setWhatIds.add(ar.get(ar));
}
If this helps, Please mark it as best answer.
Thanks ,
Lukesh
Method does not exist or incorrect signature: void get(AggregateResult) from the type AggregateResult
Invalid loop variable type expected Id was Task
Fiona
Sorry for the late reply, please try below code hope it help you. Please mark best answer if it helps.
Thank,
Lukesh