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
mr209204mr209204 

Getting an Id from page.

What I am trying to do is run a query on all Opportunity Contact Roles for a Contact and get the Opportunity Amount

The Query Looks like This
Select o.Opportunity.AMount, o.Opportunity, o.ContactId From OpportunityContactRole o WHERE o.ContactId =  ???

And that is where my problem comes in I need to get the Id from the page. I'm still new at this so any comments and suggestion are greatly appreciated.

This is what I have so far.

Code:
public class myClass 
{
Decimal x = 0;
for (Select o.Opportunity.Amount, o.OpportunityId, o.ContactId
From OpportunityContactRole o
WHERE o.ContactId = Id goes here )
{
x += o.Opportunity.Amount;
}
}

 

BritishBoyinDCBritishBoyinDC
How are you calling the class...from a button or a vf page?

If the former, you can just pass it in as an apex call.

If you are calling a VF page from the contact via a button, and displaying the results, you can pass in the Contact Id as a parameter to the page, and then reference the id in the SOQL:

public class myClass
{
Decimal x = 0;
for (Select o.Opportunity.Amount, o.OpportunityId, o.ContactId
From OpportunityContactRole o
WHERE o.ContactId = :System.currentPageReference().getParameters().get('id') )
{
x += o.Opportunity.Amount;
}
}

Look in the VF Help if you're not sure how to pass in an id into a page...