You need to sign in to do that
Don't have an account?
tschatz
Code:
In the line: Opportunity ST = [Select (Select ContactId From OpportunityContactRoles where Role = 'Ship To') From Opportunity o];
Multiple Object Troubles
Hi All,
I'm new and hoping someone can help me along. I've created a trigger that fires when an Opportunity is added or updated. It calls a class method that I have created.
The method checks to see if the Stage field is set to Closed Won, if it is the method does things. So far this is working as long as I don't have the method do to much. Basically I have it add an error to the page so I could see that it is firing, which it is.
Here's what I'm looking to do, when an Opportunity Stage is set to Closed Won, I want to find the First Name, Last Name, and Email Address of the Contact with the Contact Role of 'Ship To' (a custom role set in Salesforce) for that Opportunity.
Here's what I have in my Class so far:
public class CP_OpportunityClosedWon { public static void CP_createNewCPUser(Opportunity[] opps){ for (Opportunity o:opps){ if (o.StageName == 'Closed Won') { Opportunity ST = [Select (Select ContactId From OpportunityContactRoles where Role = 'Ship To') From Opportunity o]; //o.StageName.addError(ST.FirstName); my failed attempt to see what is contained in ST } } } }
In the line: Opportunity ST = [Select (Select ContactId From OpportunityContactRoles where Role = 'Ship To') From Opportunity o];
I'm trying to get the ContactID of the Ship To person so I can access that person's Contact information, but I'm unsure how to get there.
Any help is appriciated.
_t
Okay I figured it out. Here's what I did in case anyone else is having the same troubles.
Code: