1

I am trying to query a custom object using two variables. I used the following piece in my apex code and looked at the logs in dev console

id Pgm = 'a1Tm0000000DtjIEAS';
public list<Phone__c> lstPhone;
    lstPhone = new list<Phone__c>();
 lstPhone = [Select id,Account__c,Program__c from Phone__c where Program__c =: Pgm  limit 1]; 

When i try to print the size of the list , it shows null. Ideally it should have returned an object as i have a matching object for the criteria.

It also shows up when i query the Phone object with the following query(using fuse IT), i get one matching result

Select id,Account__c,Program__c from Phone__c where Program__c ='a1Tm0000000DtjIEAS'  limit 1

I am not sure why i am not getting the result from my apex class. Is it because it is trying to match the 15 digit id and the 18 digit id.

  • 1
    You're doing something wrong. List.size cannot return null. 15 and 18 character Id values are equivalent, as well, so that's definitely not the problem. – sfdcfox Jul 11 '16 at 22:04
  • Yeah, that's gotta be the root of the weirdness here. List size is not nillable. – Adrian Larson Jul 11 '16 at 22:32
  • The binding makes no difference - Adrian is right. Also, recreating this query with my own custom object works. Something else is wrong - perhaps we need a bigger code sample. – Caspar Harmer Jul 11 '16 at 22:33
  • 1
    You should edit your post to place this snippet in context with the outer class, and also show us how you are trying to get the size of the list. – Adrian Larson Jul 11 '16 at 22:40
  • @Dino: Have you checked if the record you are trying to query is accessible to you. i.e, you have read permission on that record(don't consider object permission)? – maniac coder Jul 12 '16 at 1:58
0

By default API query(fuse IT here) always uses the 18 digit ID and 18 digit is 'case insensitive', so whatever case you enter it will accept.

But if the ID is failing in Salesforce console which take the 15 digit and failing, that would make me guess that some where you have put the case of the ID incorrectly. I am querying in my dev org and i can get the results.

  • No, the casing is correct. Run it through one of the algorithms posted here. It's valid. – Adrian Larson Jul 11 '16 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.