You need to sign in to do that
Don't have an account?
Anoop Patel 7
I'm trying to populate a field from Opportunity to my custom object using a trigger and receiving a error
I'm trying to populate a field from Opportunity to my custom object using a trigger and receiving the following error;
Error: Compile Error: Illegal assignment from LIST<Opportunity> to MAP<Id,Opportunity> at line 13 column 7
My code;
trigger populateAccountfromOpp on Service_Item__c(after insert, after update){
Set<Id> oppIds = new Set<Id>();
Map<Id, Opportunity> oppMap;
for(Service_Item__c ser : trigger.new){
if(ser.Opportunity__c!= null){
oppIds.add(ser.Opportunity__c);
}
}
oppMap = [select Id, Account_Type__c from Opportunity where Id in : oppIds];
for(Service_Item__c ser : trigger.new){
if(ser.Opportunity__c != null && oppMap.containsKey(ser.Opportunity__c)){
ser.Account__c = oppMap.get(ser.Opportunity__c).Account_Type__c;
}
}
}
Thanks in advance for any help that can be provided
Error: Compile Error: Illegal assignment from LIST<Opportunity> to MAP<Id,Opportunity> at line 13 column 7
My code;
trigger populateAccountfromOpp on Service_Item__c(after insert, after update){
Set<Id> oppIds = new Set<Id>();
Map<Id, Opportunity> oppMap;
for(Service_Item__c ser : trigger.new){
if(ser.Opportunity__c!= null){
oppIds.add(ser.Opportunity__c);
}
}
oppMap = [select Id, Account_Type__c from Opportunity where Id in : oppIds];
for(Service_Item__c ser : trigger.new){
if(ser.Opportunity__c != null && oppMap.containsKey(ser.Opportunity__c)){
ser.Account__c = oppMap.get(ser.Opportunity__c).Account_Type__c;
}
}
}
Thanks in advance for any help that can be provided
Replace this line
with this line
All Answers
Replace this line
with this line
Standard SOQL request returns List<sObject> collection, not Map<K,V>
Should it be like this?
oppMap = new Map<Id,Opportunity>([select Id, Account_Type__c from Opportunity where Id in : oppIds]);
Yes, it should be like this.