You need to sign in to do that
Don't have an account?
Praveen Kumar Bonalu
how to query more than 2 objects in a class
How to query more than two objects in a class ?
Hi i am new to salesforce development.I have 2 standard objects say (Accounts and contacts) and 3 custom objects that are related to each other(Obj1,obj2,obj3).How do i write a query to fetch all the fields from these 5 objects and display in my visual force page(i have to render as pdf with all these fields)
Hi i am new to salesforce development.I have 2 standard objects say (Accounts and contacts) and 3 custom objects that are related to each other(Obj1,obj2,obj3).How do i write a query to fetch all the fields from these 5 objects and display in my visual force page(i have to render as pdf with all these fields)
Like :
Account acc = [ Select name from Account where Id = '001XXXXXXXXXXXX';
List<Contact> listOfContact = [ Select FirstName, LastName from Contact Where AccountiD =: acc.Id ];
List<Obj1> => Its query
List<Obj2> => Its query
List<Obj3> => Its query
As you mentioned objects have relationships you could query them in a single SOQL like account and contact are related
Account acc = [ Select name,
( Select FirstName, LastName From Contacts ) // here Contacts is relationship name
from Account where Id = '001XXXXXXXXXXXX';
Please mark this as answer if it helps you so it help others having same problem.
You cannot Query all fields with a start (*) you have to specifically mention field API names.
http://www.forcexplore.com/2014/07/relationship-query-in-salesforce.html (http://www.forcexplore.com/2014/08/visualforce-and-apex-tutorial-for-beginners.html)
http://www.forcexplore.com/2014/08/visualforce-and-apex-tutorial-for-beginners.html