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

My code doesn't work on reports
Hi All
I have the following code to take an opportunity contact role and add it to a field on the opportunity called Opprtunity_Contact__c. The code works fine however it throws up some bad results when i add the opportunity_contact__c field to reports. Does anyone know how this can happen?
Thanks
Conor
I have the following code to take an opportunity contact role and add it to a field on the opportunity called Opprtunity_Contact__c. The code works fine however it throws up some bad results when i add the opportunity_contact__c field to reports. Does anyone know how this can happen?
Thanks
Conor
trigger MnCopyPrimaryContact on Opportunity (before update) { Set<Id> setOfIds = new Set<Id>(); for (Opportunity o : Trigger.new) { if(o.Id!=Null){ setOfIds.add(o.Id); } } OpportunityContactRole[] contactRoleArray= [select ContactID, isPrimary from OpportunityContactRole where OpportunityId IN :setOfIds order by isPrimary desc,CreatedDate]; for (Opportunity o : Trigger.new) { if (contactRoleArray.size() > 0) { o.Opportunity_contact__c = contactRoleArray[0].ContactID; }else{ o.Opportunity_contact__c = null; } } }