• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Standard formats of Relationship Queries

Standard formats of Relationship Queries in Salesforce

Standard Formats of Queries:-

Child obj name variable = “select child obj field1, parent obj name.parent obj field1, parent obj name.parent obj field2 from child obj name where condition”;
System.debug (‘child obj records are’+variable);
System.debug (‘’ parent obj field1+variable .parent obj name.parent obj field1);
System.debug (‘parent obj field2+variable.parent obj name.parent objfield2);

Fetching single record form child – parent for standard objects:

List<Child obj name> variable = “select child obj field1, parent obj name.parent obj field1, parent obj name.parent obj field2 from child obj name where condition”;
System.debug (‘child obj records are’+variable);
For (child obj name variable1: variable)
{
System.debug (‘’ parent obj field1+variable1 .parent obj name.parent obj field1);
System.debug (‘parent obj field2+variable1.parent obj name.parent objfield2);
}

Fetching Multiple record form child – parent for standard objects:

List<Child obj name> variable = “select child obj field1, parent obj name.parent obj field1, parent obj name.parent obj field2 from child obj name where condition”;
System.debug (‘child obj records are’+variable);
For (child obj name variable1: variable)
{
Variable1.parent obj name.parent obj field1=’…………..’
Variable1.parent obj name.parent obj field2=’……………’
Update variable1.parent obj name;
System.debug (‘’ parent obj field1+variable1 .parent obj name.parent obj field1);
System.debug (‘parent obj field2+variable1.parent obj name.parent objfield2);

Updating Multiple record form child – parent for standard objects

List<Parent obj name> variable= “select fieldname1 (select field1, field2 from parent obj name.childs obj)from parent obj name where condition”;
System.debug (‘parent obj records’+variable1);
For (parent obj name variable1: variable)
{
For (child obj name variable2:variable1.child plural obj name)
{
System.debug (‘child obj field1’+variable2);
System.debug (‘child obj field2’+variable2);
}
}
Enthusiastic about exploring the skill set of Salesforce? Then, have a look at the Salesforce Training Online to gather additional knowledge.

Fetching Multiple record form Parent – child for standard objects:

List<Parent obj name> variable= “select fieldname1 (select child obj field1, child obj field2 from parent obj name.child plural obj) from parent obj name where condition”;
System.debug (‘parent obj records’+variable1);
For (parent obj name variable1: variable)
{
For (child obj name variable2:variable1.child plural obj name)
{
Variable2.child obj field1='……….';
Variable2.child obj field2='……….';
update variable2;
System.debug (‘child obj field1’+variable2);
System.debug (‘child obj field2’+variable2);
}
}

 Updating Multiple record form Parent – child for standard objects:

list<parent obj API name> variable=“select parent obj field1 ,(select child obj field1,child obj field2
from parent obj API name.child plural obj name__r) from parent object API name where condition);
System.debug (' parent object records'+variable); for (parent obj API name variable1:variable)
{
For(child obj singular name__c variable2:variable1.child plural obj name__r)
{
Variable2.field1 API name='………..'; Variable2.field2 API name='……….'; update variable2;
System.debug ('field1'+variable2);
System.debug ('field2'+variable2);
}
}

Updating Multiple record form Parent – child for custom objects:

list<child obj API name> variable=“select child obj field1,parent obj name __r.field1 from child obj API
name where condition”; system.debug ('child obj records are'+variable);
for( child obj API name variable1:variable)
{
Variable1.parent obj singular name__r.field1 API name='…….'; update variable1.parent obj singular name__r;
system.debug('parent obj records'+variable1.parent obj singular name__r.field1 API name);
}

For indepth understanding on Salesforce click on

 

Summary
Review Date
Reviewed Item
Standard formats of Relationship Queries
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Standard formats of Relationship Queries"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.