function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The WalrusThe Walrus 

system.debug display of a single field

I have the following query and debug statements:

 

Invoice_Balance__c[] b = [SELECT Invoice_Balance_Date__c, Invoice_Balance_Amount__c, Invoice__r.Name 
FROM Invoice_Balance__c WHERE Invoice__r.Name LIKE :xxx
ORDER BY Invoice_Balance_Date__c DESC NULLS LAST LIMIT 1];
//
System.debug('b: '+b);
System.debug('b: '+Invoice_Balance__c.Invoice_Balance_Amount__c[b]);

 The first system.debug statement works, but the second generates this error:

 

Error: Compile Error: Expression must be a list type: Schema.SObjectField at line 18 column 20

 

What do I need to change in the second statement?  Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

Am not sure what exactly you are trying to do with this

 

System.debug('b: '+Invoice_Balance__c.Invoice_Balance_Amount__c[b]);

 But if you were trying to fetch the value from particular index then you can do something like this

 

System.debug('b: '+ Invoice_Balance__c[0].Invoice_Balance_Amount__c);

 

Also complete code to debug all values is below :

 

List<Invoice_Balance__c> b = [SELECT Invoice_Balance_Date__c, Invoice_Balance_Amount__c, Invoice__r.Name 
FROM Invoice_Balance__c WHERE Invoice__r.Name LIKE :xxx
ORDER BY Invoice_Balance_Date__c DESC NULLS LAST LIMIT 1];

System.debug('b: '+b);
for(Invoice_Balance__c temp : b)
	System.debug('b: '+ temp.Invoice_Balance_Amount__c);

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

All Answers

Devendra@SFDCDevendra@SFDC

 

Try this:

 

Invoice_Balance__c b = [SELECT Invoice_Balance_Date__c, Invoice_Balance_Amount__c, Invoice__r.Name 
FROM Invoice_Balance__c WHERE Invoice__r.Name LIKE :xxx
ORDER BY Invoice_Balance_Date__c DESC NULLS LAST LIMIT 1];
//
System.debug('b: '+b);
System.debug('Inv Balance Amount '+b.Invoice_Balance_Amount__c);

 

Hope this helps.

 

Thanks,

Devendra

Ankit AroraAnkit Arora

Am not sure what exactly you are trying to do with this

 

System.debug('b: '+Invoice_Balance__c.Invoice_Balance_Amount__c[b]);

 But if you were trying to fetch the value from particular index then you can do something like this

 

System.debug('b: '+ Invoice_Balance__c[0].Invoice_Balance_Amount__c);

 

Also complete code to debug all values is below :

 

List<Invoice_Balance__c> b = [SELECT Invoice_Balance_Date__c, Invoice_Balance_Amount__c, Invoice__r.Name 
FROM Invoice_Balance__c WHERE Invoice__r.Name LIKE :xxx
ORDER BY Invoice_Balance_Date__c DESC NULLS LAST LIMIT 1];

System.debug('b: '+b);
for(Invoice_Balance__c temp : b)
	System.debug('b: '+ temp.Invoice_Balance_Amount__c);

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

This was selected as the best answer
The WalrusThe Walrus

Wow.  Very cool. Thanks

 

What I was trying to do was exactly what your code snippet does - present the result of my Select statement, but only the one field - the Invoice_Balance_Amount__c.  So basically, even though I limited my selection to one, I was not placing the result in a list.  

 

Thanks again, this is very helpful.   

Ankit AroraAnkit Arora

Am happy that it helped you.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page