You need to sign in to do that
Don't have an account?
GMASJ
Opportunity and Campaign
Hi,
There is very old trigger logic written in our instance this is failing due to not being bulkified can someone please suggest how to bulkifie below trigger
Sam
There is very old trigger logic written in our instance this is failing due to not being bulkified can someone please suggest how to bulkifie below trigger
trigger updateprimarycampaign on Opportunity (Before Update ,After insert) { if ( checkRecursive_updateprimarycampaign.runOnce()) { if(Trigger.isUpdate) { try { for (Opportunity op : Trigger.new) { CampaignMember cm = [SELECT CampaignId FROM CampaignMember where ContactId = :op.Contact__c and HasResponded = true and CreatedDate <= :op.createddate limit 1]; if ( cm.CampaignId == NULL) { op.CampaignId = null; } else { op.CampaignId = cm.CampaignId; } } } catch (Exception e) { for (Opportunity op : Trigger.new) { op.CampaignId = null; } } } else if (Trigger.isInsert) { Set<ID> setoppId = new Set<Id>(); String getCampaignId; for(Opportunity opp: Trigger.new ) { setoppId.add(opp.id); } List<Opportunity> lstOpp = [select id , CampaignId from Opportunity where id in :setoppId ]; try { List<Opportunity> lstOppToUpdate = new List<Opportunity>(); for (Opportunity op : lstOpp) { CampaignMember cm = [SELECT CampaignId FROM CampaignMember where ContactId = :op.Contact__c and HasResponded = true and CreatedDate <= :op.createddate limit 1]; if ( cm.CampaignId == NULL) { op.CampaignId = null; lstOppToUpdate.add(op); } else { op.CampaignId = cm.CampaignId; lstOppToUpdate.add(op); } } if(lstOppToUpdate.size() > 0 ) { update lstOppToUpdate; } } catch (Exception e) { /* for ( Opportunity op : lstOpp ) { op.CampaignId = null; } update lstOpp; */ update lstOpp; } } } }Thanks
Sam
Try the below code:
Hope this will be helpful.
Thanks.
All Answers
Try the below code:
Hope this will be helpful.
Thanks.
I need your help in building test class to get 75+ code coverage
Below is the old test class which is giving 62% code coverage. need your suggestion to improve the coverage.
Thanks
Sudhir
Try the below code:
Hope it will be useful.
Thanks.