You need to sign in to do that
Don't have an account?
Nicholas Palattao
Can't enter SOQL for loop
I wrote a small trigger to populate a lookup field on the Opportunity object, and I can't seem to get my test class to enter the loop which contains the assignment of this field. The query appears to have all the necessary info, I'm not sure what's wrong.
Here is the trigger:
trigger FillPrimaryPartner on Opportunity (before insert, before update) { for (Opportunity opp : trigger.new){ for (Partner p : [select id from Partner where IsPrimary=true and AccountFromId =: opp.AccountId]){ opp.Primary_Partner__c = p.Id; } } }and here is its test class:
@isTest public class TESTFillPrimaryPartner { static testMethod void insertNewData(){ Account partAcct = new Account(); partAcct.Type = 'Signed Partner'; partAcct.Industry = 'Retail'; partAcct.BillingCountry = 'Italy'; insert partAcct; Account oppAcct = new Account(); oppAcct.Type = 'Customer'; oppAcct.Industry = 'CPG'; oppAcct.BillingCountry = 'Italy'; insert oppAcct; Opportunity opp1 = new Opportunity(); Opportunity.AccountId = oppAcct.Id; insert opp1; Partner part1 = new Partner(); part1.IsPrimary = true; part1.AccountFromId = oppAcct.Id; part1.AccountToId = partAcct.Id; insert part1; } }
Try:
All Answers
Try: