You need to sign in to do that
Don't have an account?

Triiger Issue-Incompatible element type Id for collection of Opportunity
Hi, While writing this trigger, I am getting this error below marked as underline-
Incompatible element type Id for collection of Opportunity
Please help to resolve the issue
Thanks,
Kaity
Incompatible element type Id for collection of Opportunity
Please help to resolve the issue
trigger UpdateOpportunity on Top_X_Designation__c (after Insert, after Update, after Delete) { List<Opportunity> lstopp = new List<Opportunity>(); List<Opportunity> lstOppUpdated = new List<Opportunity>(); // Set<Id> lstOppUpdated = new Set<Id>(); Map <Id, Id> docAttachTrue = new Map<id,id>(); Map <Id, Id> docAttachFalse= new Map<id,id>(); Map <Id, Id> docAttachDel = new Map<id,id>(); Set<id> opptySetId = new Set<id>(); Set<id> opptySetDel = New Set<id>(); if(Trigger.IsInsert || Trigger.IsUpdate){ for(Top_X_Designation__c txd: Trigger.new){ if(txd.Type__c=='Contract Flow Down/Handoff' && txd.Document_Attached__c == True ){ docAttachTrue.put(txd.Opportunity__c, txd.id); opptySetId.add(txd.Opportunity__c); } else docAttachFalse.put(txd.Opportunity__c, txd.id); opptySetId.add(txd.Opportunity__c); } } if(Trigger.IsDelete){ for(Top_X_Designation__c txdold: Trigger.old){ docAttachDel.put(txdold.Opportunity__c, txdold.id); opptySetId.add(txdold.Opportunity__c); opptySetDel.add(txdold.Opportunity__c); } } lstopp = [SELECT ID, Handoff_Attached__c FROM Opportunity WHERE id in : opptySetId]; if(lstopp.size()>0 && lstopp!= null){ for(Opportunity opp:lstopp){ if(docAttachTrue.containsKey(opp.id)){ opp.Handoff_Attached__c = 'Yes'; } if(docAttachFalse.containsKey(opp.id)){ opp.Handoff_Attached__c = 'No'; } if(opptySetDel.contains(opp.id)){ opp.Handoff_Attached__c = ''; } lstoppUpdated.add(opp.id); //Error: Incompatible element type Id for collection of Opportunity } if(lstoppUpdated.size()>0 && lstoppUpdated != null){ update lstoppUpdated; } } }
Thanks,
Kaity
The list lstoppUpdated is of Opportunity type. You are trying to add Id into the Opportunity list.
You can change the code to:
or you can change the type of the list to Id type at the top, like
Hope this resolves. If it does kindly mark it as the best answer :)
DML requires SObject or SObject list type: List<Id>
So you need to keep the list of Opportunity type only and change the line no 50 to:
And keep the list as it was before: