I am trying to build a visual force page, where you select an opportunity, and then you select stages associated with that opportunity. Opportunities are saved in the table RecordTypes, and Stages are saved in the table OpportunityStage.
In what table is the relationship saved?
RecordTypes aren’t a table, they’re literally a set of types defined for a specific object, so that any record of that object (for example any Opportunity) can have one of those types. It’s basically a super special field on the object which is used to drive a whole heap of behaviours — you can have different page layouts for each record type, different picklist values, you could customise validation rules etc..
Stages again are a ‘special’ part of Salesforce configuration as they belong to the Sales process, and I believe the values available depend on the record type (i.e. they act just like a picklist).
Long story short, you don’t need to worry about any relationship for these fields, in database terms they’re columns on the opportunity table, in SFDC terms they’re fields on the Opportunity object.
Edit
Following clarification of the requirements, i.e needing the available stage names for two opportunities.
There are easy to get using Visualforce without any describe information.
Ensure your sales processes are defined and linked to appropriate record types for the Opportunities (sounds like this has already been done). Next, simply load the required opportunities using a custom controller (or controller extension) — you could specify them via page parameters as below, though this is a contrived example and does not include any error handling etc. (or opportunity selection):
Then simply use
<apex:inputField>to put theStageNamefield onto the page:When you want to do your search for accounts, you can just use the
StageNamefield on bothopptyandoppty2in your controller. The query will be something like the following (untested):The problem with this of course, is that it’ll return ALL accounts so I think you’d be better off searching on
OpportunitywhereStageNameequals that ofoppty1returning the relavant details and also associated account ID. then do a second query to find opportunities whereStageNameequals that ofoppty1and the account id is in the set of account IDs located in the first query. You’re still likely to run into issues with returning too many records, so you may find a way to refine this method or you could specify other parameters as well (for example, opportunities closing this month).