You need to sign in to do that
Don't have an account?
Douglas Molina
Create custon Visualforce page list, from Apex SOQL query with filds from multiple Objects
Hi,
I have in my Org the WorkOrder and WorkOrderLineItens Objects.
I want to display the result of a very specific SOQL query in a Visualforce page.
The point is, in my Apex SOQL query, I bring fields from both objects, and others related... so, how can I declare a single List to receive this SOQL result, with all the returned fields, from all objects?
I'm following this article, but It only uses fields fron a single object, so the List is declared based on that object..
https://help.salesforce.com/articleView?id=000205631&type=1
My SOQL looks like this:
In developer console, it runs fine:
Some sugestion, or other reference that could help me on it?
Thanks.
I have in my Org the WorkOrder and WorkOrderLineItens Objects.
I want to display the result of a very specific SOQL query in a Visualforce page.
The point is, in my Apex SOQL query, I bring fields from both objects, and others related... so, how can I declare a single List to receive this SOQL result, with all the returned fields, from all objects?
I'm following this article, but It only uses fields fron a single object, so the List is declared based on that object..
https://help.salesforce.com/articleView?id=000205631&type=1
My SOQL looks like this:
select id, LineItemNumber, PricebookEntry.Product2.Name, WorkOrder.WorkOrderNumber, WorkOrder.Tipo_de_Servi_o__c FROM WorkOrderLineItem WHERE UnitPrice = 0 AND WorkOrder.CreatedDate >= 2017-05-15T00:00:00.000+0000 ORDER BY LineItemNumber ASC
In developer console, it runs fine:
Some sugestion, or other reference that could help me on it?
Thanks.
Yes you can put the query result in list. and access that on visulforce page. For example
Put the query in lstObjects list. Make the list as property
Apex class
VF page:
Hope this will help you.
Thanks,
Sukanya Banekar
All Answers
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using" target="_blank)
Yes you can put the query result in list. and access that on visulforce page. For example
Put the query in lstObjects list. Make the list as property
Apex class
VF page:
Hope this will help you.
Thanks,
Sukanya Banekar
So if your SOQL query is having FROM WorkOrderLineItem then you should prepare the list of object type WorkOrderLineItem and the result will be stored in it.
Your sugestions worked fine, and helped me to understand these lists.
I thought the list of objects could not hold related objects fields, cause I was reciving some "invalid field" error messages on saving the visualforce page.
The problem is that I was referring to a related object field, just writing its name after the var name .. without the relationship field name between them.
Now it's working as I spected.
Follow is the reduced version of the Apex Class:
And the visualforce page:
The result page:
Thank you again!