Monday 22 September 2014

In salesforce SOQL there are two type of subquery.

1. from parent object to the child object subquery .

suppose you try to fetch Account(parent) records and related all Contacts(child)

then use this subquery

list<Account> lstAccountToContact = [select Id,Name,(select Id,Name from Contacts) from Account];

system.debug(lstAccountToContact.get(0).Contacts.Name);

2. from child object to the parent object subquery.

list<Contact> lstContactToAccount = [select Id,Name,Account.Id,Account.Name from Contact];

system.debug(lstContactToAccount.get(0). Account.Name);


You can store child records with related parent Id into the list

First create the list and store the child and parent records into the list .

list<Parent> lstParent = new list<Parent>();

for(Parent objParent :[select Id,Name,(select Name from child__r order by Name)
                                                                                                       from Parent order by Name])
{
lstParent.add(objParent);
}

you can fetch the child values from the list


system.debug('-----------child.Name'lstParent.get(0).child__r);

try to use this on the developer console.

I searched on google for so many staff related to the sfdc ...there are so many web ,blog you can find ....I always use these website for my requirement..

Infallible Techie   

SFDC POINT  

Salesforce Tips and Tricks


I learned so many things from these website ..I want to share those stuff.
All the knowledge i got from so many website, blog . Thanks to them first