function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CprocessingCprocessing 

Novice Question - Related Objects - Sorry

Hi Guys,

 

I feel a bit daft as i just can't work out how to access related objects within the trigger.

 

My structure is something like this:

 

Rep < Account > Return

 

And i'd like to get information from REP to process the return.

 

trigger get_REP_Email on Return__c (before update) {
	
	Return__c myReturn = trigger.new[0];

}

 Above is all i've managed to get so far, and i've tried many things. What i'd like to do is on update, take the return object - Find the related Account Object - Find the related rep object and base a condition in the return object on the rep object?

 

Can this be done?

 

Can anybody point me in the right direction?

 

Kind Regards,

CP

Best Answer chosen by Admin (Salesforce Developers) 
edwin_beltranedwin_beltran

you have to create an instance of the Return__c and look inside the trigger.new...

 

trigger get_REP_Email on Return__c (before update) {
	for (Return__c myReturn : trigger.new) {
            // now you can access fields of the customer object Return__c
            myReturn.name = 'WhatEver';
            // etc...
}

}

 

and then you can access objects just like the post prior to mine.... hopes this help.

 

_e

All Answers

Mike@COLMike@COL

You should be able to get access to the ID of the account like this: (Assuming the name of the relationship field between Return and Account is "Account__c")

 

myReturn.Account__c.Id

 

Then you can do an SOQL query to get the Reps related to th account like this: (Again this assumes the name of the relationship field between Rep and Account is "Account__c")

 

[SELECT ID FROM REP WHERE REP.Account__c = : myReturn.Account__c.Id];

 

edwin_beltranedwin_beltran

you have to create an instance of the Return__c and look inside the trigger.new...

 

trigger get_REP_Email on Return__c (before update) {
	for (Return__c myReturn : trigger.new) {
            // now you can access fields of the customer object Return__c
            myReturn.name = 'WhatEver';
            // etc...
}

}

 

and then you can access objects just like the post prior to mine.... hopes this help.

 

_e

This was selected as the best answer