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

before insert trigger: apex variable in soql causes error?
Here is my code:
for (Orderc__c o : trigger.new){ if(o.Has_Promotion_Code__c == true && o.Promotion_Code__c !=null){ Opportunity[] findOpp = [SELECT Name FROM Opportunity WHERE Voucher_Code__c = :o.Promotion_Code__c limit 1]; } if(findOpp.size()==1){ o.Ready_To_Print__c = false; o.Pay_Status__c = 'INVOICE'; } }
error message on line 6: method does not exist or incorrect signature:findOpp.size()
ok, Thanks.
why do I have to seperate the define and the soql?
Scoping - when you define it inside the if statement, it is only scoped for that block of code. Once you finish the if statement, the variable no longer exists. By defining it at the outer level, its available until that outer level block finishes.