This Objects can be top level Objects, parents, as they are also called or Child Objects.
Oracle Sales Cloud puts at our disposal 3 ways we can access these Objects:
1 - Related Collection Attribute
This attribute is created by the system for us when we have a relationship of 1 : M or M:M between 2 objects. It can exist out of the box for standard objects or is created when we make a custom Dynamic Choice List or a Relationship (using relationships in Application Composer).
For example, in the Opportunity Object, there is a Child Object called Opportunity Revenue, indicating a 1 to Many (1:M) relationship. The system creates an attribute called ChildRevenue in the Opportunity Object.
Let's say we want to sum up all the quantities in the Revenue lines of an Opportunity:
def vQuatity = 0
def revChild = ChildRevenue
while(revChild.hasNext()) {
def row = revChild.next()
vQuatity += row.Quantity
}
return vQuatity
The general form for accessing Related Collections:
def varName = ""
def collectionView = NameOfTheCollection
while(collectionView.hasNext()) {
def row = collectionView.next()
varName = row.FieldNameFromCollectionObject
}
return varName
2 - Related Object Attribute
Related objects are attributes indicating a single record from an external Object connected to our current record. For example, in Opportunity Revenue, we can get the Opportunity name like this:
def vName = Opportunity?.Name
If we made a custom DCL pointing to Opportunity:
DCLname_Obj_c?.Name
Search for Related Object Attributes and Related Object Collections in the pallet:
Go to Fields, switch the searching parameters to Type, and search %Related%
3 - Use newView() Method
This is used when there is no relationship between the Object in which context we are and the Object we want to get data from.
Basic structure of using newView():
// Use the newView() function to get a view object
def vo = newView('OBJECT_NAME')
// Create a new view criteria
def vc = newViewCriteria(vo)
// Create a new view criteria row
def vcr = vc.createRow()
// Create a view criteria item
def vci1 = vcr.ensureCriteriaItem('FIELD_API_NAME_FROM_OBJECT')
// Set the operator of the first view criteria item
vci1.setOperator('=')
// Set the value of the first view criteria item
vci1.setValue(A_VALUE)
// Set the text field criteria to be case-insensitive
vci2.setUpperColumns(true)
// Add the new view criteria row
vc.insertRow(vcr)
// Append the view criteria to the view object
vo.appendViewCriteria(vc)
// Execute the query
vo.executeQuery()
while(vo.hasNext()) {
def row = vo.next()
varName += row.FieldName
}
Simplified version:
def vo = newView('TroubleTicket_c')
vo.appendViewCriteria("AssignedTo_Id_c = 1089003 and Status_c = 'Working'")
vo.executeQuery()
if(vo.hasNext()) {
def row = vo.next()
// Do something with the current result row
}
Example:
We have a field with a Resource name and need to get the 'ResourceProfileId'. The object is called abc.
We expect only one record, so we can skip the while loop:
return view_Resource.first()?.ResourceProfileId
newView() explanation: