You need to sign in to do that
Don't have an account?
Error: Compile Error: Incompatible element type String for collection of Integer at line 5 column 9
trigger SetContactOnOrderItem on Line_item__c (before update, before insert) {
Set<Integer> lineitemnumbers = new Set<Integer>();
for (Line_item__c collectNumFromLineitem : Trigger.new) {
lineitemnumbers.add(collectNumFromLineitem.Name);
}
List<Opportunity> oppList = [SELECT id, Related_Sponsorship_Offer__c
FROM Opportunity WHERE Related_Sponsorship_Offer__c IN :lineitemnumbers];
Map<Integer, Opportunity> lineitemNumToOppMap = new Map<Integer, Contact>();
for (Opportunity c : oppList) {
lineitemNumToOppMap.put(c.Related_Sponsorship_Offer__c, c);
}
for (Line_item__c o : Trigger.new) {
if (o.Name != null) {
o.Opportunity__c = lineitemNumToOppMap.get(o.Name).id;
}
else {
o.Opportunity__c = null;
}
}
}
I have a custom object named: Line_item__c and a standard object called opportunity. The custom object has a lookup field for an opportunity. The opportunity page also has a lookup field for the custom object. When a opportunity look up field is populated on the custom object, it should autopopulate the related Line item on the look up field on the opportunity. I tried this trigger but I get the following error. I am new the apex and any help would be appreciated.
Thank you
Try below code and let me know.
Best Regards,
-Vivek