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
Filipe BaradelliFilipe Baradelli 

How to get product data?

I need to get the name, description, quantity .... of this product. But it is inside a subquery.
nomeproduto=[SELECT Items__c,Total_Cost__c,Account__c,Id,(SELECT Id,Product__c,Product_Short_Description__c,Product_Price__c,Product_Name__c,Quantity__c,VF_Image__c FROM Catalog_Line_Items__r) FROM Catalog_Order__c WHERE Status__c = 'Cart' AND CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];
Can someone help me?
 
Best Answer chosen by Filipe Baradelli
Ravi Dutt SharmaRavi Dutt Sharma
I think below code should work, I have not compliled it though.
 
List<Catalog_Order__c> nomeproduto=[SELECT Items__c,Total_Cost__c,Account__c,Id,(SELECT Id,Product__c,Product_Short_Description__c,Product_Price__c,Product_Name__c,Quantity__c,VF_Image__c FROM Catalog_Line_Items__r) FROM Catalog_Order__c WHERE Status__c = 'Cart' AND CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];

for(Catalog_Order__c ctlgOrdr : nomeproduto){
	for(Catalog_Line_Item ctlgLineItem : ctlgOrdr.Catalog_Line_Items__r){
		System.debug(ctlgLineItem.Product__c);
	}
}

 

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
I think below code should work, I have not compliled it though.
 
List<Catalog_Order__c> nomeproduto=[SELECT Items__c,Total_Cost__c,Account__c,Id,(SELECT Id,Product__c,Product_Short_Description__c,Product_Price__c,Product_Name__c,Quantity__c,VF_Image__c FROM Catalog_Line_Items__r) FROM Catalog_Order__c WHERE Status__c = 'Cart' AND CreatedById =:UserInfo.getUserId() ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT 1];

for(Catalog_Order__c ctlgOrdr : nomeproduto){
	for(Catalog_Line_Item ctlgLineItem : ctlgOrdr.Catalog_Line_Items__r){
		System.debug(ctlgLineItem.Product__c);
	}
}

 
This was selected as the best answer
Filipe BaradelliFilipe Baradelli
How could I get, for example, the name of the product? (I understand what this code do, but I must find the syntax to make it get the data).