Standard formats of Relationship Queries

Ratings:
(4)
Views:0
Banner-Img
  • Share this blog:

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);
}

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox