+ Start a Discussion

Admin needs help with a controller

Hi All,

How do you pass an ID from a lookup field to a controller from a record that hasn't been saved yet?

I have been writing nothing but triggers for a while now, and only have minimal experience with controllers.

Here is what I am trying to do. 


SchoolWorkPlanNarrative__c(narrative) has a lookup to the Account Object.

nvpsDeployedStrategy__c(strategy) has a lookup to the Account Object, too.

I have a created junction object between these two objects So that a Narrative record can be tied to more than one Strategy record. 


What I want to do is create a VF page that will launch from the Narrative related list on the Account page layout that will allow the user to enter their narrative and then select at least one or as many strategies as there are that belong to the same Account that the Narrative was launched from and insert them as junction object records.


So write away I'm running into trouble...how do I get that Account ID that should be in the lookup field of the Narrative object? I'm confused because it should be there, somewhere, if the New button was clicked from the Account page right? Since the Narrative record has not been saved yet, I'm not sure how to get it. 


I have written a little bit so far, and as you can see I don't know how to query for the account.



public with sharing class narrativeWizard_Controller {
	public String selectedNarrativeID { get; set; }
	public SchoolWorkPlanNarrative__c selectedNarrative { get; set; }
	public List<StrategyNarrative__c> juncObs { get; set; }
	public List<nvpsDeployedStrategy__c> strategies { get; set; }
	//sets up base list of the available strategies
	public Set<ID> myStrategies = new Set<ID>();
	public void setUPStrategies() {
		for(nvpsDeployedStrategy__c ds : [select ID from nvpsDeployedStrategy__c where Account__c = ?]) {




Best Answer chosen by Admin (Salesforce Developers)