You need to sign in to do that
Don't have an account?
Saranya M
Illegal assignment from list<event> to sobject. Please help me in modifying the code.
I'm trying to update activity custom field - contact sys id with the value from sys id or siebel id based on the id type field
trigger ContactSysID on Event (before insert) { ID evid; for (event e:trigger.new){ evid=e.whatid; } event e=[select id,contact_sys_id__c from event where whatid=:evid]; Merchandise__c merch=[SELECT TYPEOF What WHEN Merchandise__C THEN name,id_type__C,sys_id__c,siebel_id__C END FROM event where WHAT.TYPE='Merchandise__c' limit 1]; For (Merchandise__C m:merch){ if(m.id_type__C=='Sys ID'){ e.Contact_sys_ID__c=m.sys_id__c; } else{ e.contact_sys_id__C=m.siebel_id__C; }
}
trigger ContactSysID on Event (before insert) { ID evid; for (event e:trigger.new){ evid=e.whatid; } event e=[select id,contact_sys_id__c from event where whatid=:evid]; Merchandise__c merch=[SELECT TYPEOF What WHEN Merchandise__C THEN name,id_type__C,sys_id__c,siebel_id__C END FROM event where WHAT.TYPE='Merchandise__c' limit 1]; For (Merchandise__C m:merch){ if(m.id_type__C=='Sys ID'){ e.Contact_sys_ID__c=m.sys_id__c; } else{ e.contact_sys_id__C=m.siebel_id__C; }
}
I'm Shingo.
This SOQL will return List<Event>, not single Event.
That's why you got above error.
You can modify it by adding "LIMIT 1" to the SOQL.
How can I restrict the below trigger to work only for Contact object and not get fired for other objects.
trigger ContactSysIDEvent on Event (before insert) {
IDevid;
for (event e:trigger.new)
{
evid=e.whoid;
contact m123 =[select name,id_type__C,sys_id__c,siebel_id__C from contact where id=:evid];
if(m123.id_type__C=='Sys ID')
{ e.Contact_sys_ID__c=m123.sys_id__c; }
else
{ e.contact_sys_id__C=m123.siebel_id__C; }
}
}