You need to sign in to do that
Don't have an account?
Kevin Ocie
IF-Else not working
I am trying to filter records based on the below if-else condition in apex code
if (salesId != NULL) { List<Entity__c> entity = [SELECT Status__c, Item__r.Vendor_ID__c FROM Entity__c WHERE Id = :salesId]; } else { List<Entity__c> entity = [SELECT Status__c, Item__r.Vendor_ID__c FROM Entity__c WHERE Item__r.Vendor_ID__c = :vendorId]; }
Error: Variable does not exist entity
Is it even possible to write SOQL query in IF-Else like this into the same variable? I tried to look for example where SOQL is written in If-else and could not find any..
Thanks.
if (salesId != NULL) { List<Entity__c> entity = [SELECT Status__c, Item__r.Vendor_ID__c FROM Entity__c WHERE Id = :salesId]; } else { List<Entity__c> entity = [SELECT Status__c, Item__r.Vendor_ID__c FROM Entity__c WHERE Item__r.Vendor_ID__c = :vendorId]; }
Error: Variable does not exist entity
Is it even possible to write SOQL query in IF-Else like this into the same variable? I tried to look for example where SOQL is written in If-else and could not find any..
Thanks.
I don't think there is an issue with the code. SOQL query in if and else is allowed. Are you sure the issue is coming from this block of code?