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

Condition based SOQL
Hi,
I wrote below code to test conditional SOQL based on the value we have
In below code when country != null it must return a soql value when zip != null it must return another soql value but its not working and going to a exception clause can you please suggest me what is the mistake in the code.
Thanks
Sudhir
I wrote below code to test conditional SOQL based on the value we have
In below code when country != null it must return a soql value when zip != null it must return another soql value but its not working and going to a exception clause can you please suggest me what is the mistake in the code.
Try { lead ld = [select id,postalcode,state,country from lead where id = '00Q180000029Ujz' limit 1]; system.debug('Lead ID:' + ld.id); system.debug('Postal Code:' + ld.postalcode); system.debug('State:' +ld.state); system.debug('Country:' + ld.country); Integer intzip; intzip=Integer.valueof(ld.postalcode); String lstate; lstate = ld.state; String lcountry; lcountry = ld.country; system.debug('Updated Zip:' + intzip); system.debug('State:' + lstate); system.debug('Country:' + lcountry); if ( lcountry != null ) { Territory_Lookup__c tl = [select Theater__c,Region__c,Area__c,User__c FROM Territory_Lookup__c where Country__c = :lcountry]; system.debug('Theater1 :' + tl.Theater__c); system.debug('Region1 :' + tl.Region__c); system.debug('Area1 :' + tl.Area__c); system.debug('User1 :' + tl.User__c); } if ( intzip != null ) { Territory_Lookup__c tl = [select Theater__c,Region__c,Area__c,User__c FROM Territory_Lookup__c where Zip_Start__c <= :intzip and Zip_End__c >= :intzip]; system.debug('Theater2 :' + tl.Theater__c); system.debug('Region2 :' + tl.Region__c); system.debug('Area2 :' + tl.Area__c); system.debug('User2 :' + tl.User__c); } } Catch (Exception e) { system.debug('Lookup no found'); }
Thanks
Sudhir
Hello Sudhir,
Try to modify the code to below and try ,
PLEASE SELECT THIS AS THE RIGHT ANSWER, IF YOU LIKE IT.
Thanks,
Rohit Alladi
All Answers
Hello Sudhir,
Try to modify the code to below and try ,
PLEASE SELECT THIS AS THE RIGHT ANSWER, IF YOU LIKE IT.
Thanks,
Rohit Alladi
Please try below code
Please let me know if the helps.
As a common practice, if your question is answered, please choose 1 best answer.
Additionaly you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Arun
Thanks
Sudhir