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
Ravi ParameswaranRavi Parameswaran 

list retuned from database query

Hi,
I am new to sales force development. I have question on the SOQL query and using it in the list. If it has the child reference need to check to make some actions.it is throwing the error "Invalid field Asset_Options__r for Customer_Asset__c". I am sending herewith the code snippet. Any pointers in this regards is highly appreciated.

Regards,
Ravi

code snippet
==========
1) The SOQL query is something like this [ soql = select Id, Last_Maintenance_Date__c, (select Id, Value__c from Asset_Options__r where (Name = 'SOMETST')) from Customer_Asset__c  limit 1]
  
2) Building the list
    list<Customer_Asset__c> asset = database.query(soql);      

3) Action for the child objects
   for(sobject ca : asset) {
     ...
    ....
    sobject ao;
    system.debug(ca.get('Asset_Options__r'));
 //   ao = ca.get('Asset_Options__r');
 //   if(ao != null) {
//      ... do something
//    } else {  -- do something..
//   }
  ...
  ...
   }
 
Rahul Kumar 151Rahul Kumar 151
You Can't Write this in Soql ...............
[select Id, Last_Maintenance_Date__c, (select Id, Value__c from Asset_Options__r where (Name = 'SOMETST')) from Customer_Asset__c  limit 1]

 SELECT Id, FirstName__c, Mother_of_Child__r.FirstName__c FROM Daughter__c WHERE Mother_of_Child__r.LastName__c LIKE 'C%'

You Can fire Directly this Query and Get Result ............

for any help please check Link Below
https://developer.salesforce.com/docs/atlas.en-us.200.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_and_custom_objects.htm