• KenAllred
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies

I am struggling with an extension class and being able to access the properties of the controller class.

 

I am creating a new opportunity wizard to ensure that specific data is always entered when our sales reps create a new opportunity. As part of this effort, I've also over-written the lookup window for the Account lookup (leveraging this awesome post: Roll Your Own Salesforce "Lookup" Popup Window). On the second page of my wizard, after the user has selected an Account, I have them select the contacts and contact roles that will be associated with the opportunity. I want to over-write the lookup window for Contacts as well and limit the contacts displayed to only contacts that are associated with the Account the user selected in step one of the wizard.

 

My approach was to create a class that would be an extension for the Contact Lookup page and the controller for this page would be my custom controller that I'm using for the new opportunity wizard. My thinking here was that I need to be able to get access to the Account ID that the user selected in step one, so that I can use that to filter the contacts that I display in the contact lookup page.

 

However, I must not be understanding something basic here because I can't seem to get access to the custom controller's properties.

 

My assumption is that when the CustomContactLookupController is called that the createNewOpportunity controller is calling the constructor for CustomContactLookupController and passing a reference to itself? So, I should be able to access the properties of the controller class (e.g. I have a property "tempAcc" that I use to store the Account ID of the account the user selected in step one of the opportunity wizard).

 

However, when I look at the debug log it's showing that values are "null" in the constructor method for my CustomContactLookupController when I would expect them not to be? It's like it's creating a new instance of createNewOpportunity and passing that to the constructor?

 

Here's my controller class:

 

public with sharing class createNewOpportunity
{
	Public Opportunity opportunity {get; set;}
	Public Account tempAcc {get; set;}
	Private Final Id currentUserId {get; set;}
	Public List<Opportunity> openOpps {get; set;}
		
	Public Contact contact1 {get; set;}
	Public Contact contact2 {get; set;}
	Public Contact contact3 {get; set;}
	Public Contact contact4 {get; set;}
	Public Contact contact5 {get; set;}

	Public OpportunityContactRole role1 {get; set;}
	Public OpportunityContactRole role2 {get; set;}
	Public OpportunityContactRole role3 {get; set;}
	Public OpportunityContactRole role4 {get; set;}
	Public OpportunityContactRole role5 {get; set;}
	
	
	public createNewOpportunity()
	{
		opportunity = new Opportunity();
		opportunity.StageName = 'Buyer Needs';		
		opportunity.OwnerId = UserInfo.getUserId();
		opportunity.ForecastCategoryName = 'Omitted';
		opportunity.Probability = 0;
	
		tempAcc = new Account();
		currentUserId = UserInfo.getUserId();

		role1 = new OpportunityContactRole();
		role1.opportunityId = opportunity.id; 

		role2 = new OpportunityContactRole();
		role2.opportunityId = opportunity.id;

		role3 = new OpportunityContactRole();
		role3.opportunityId = opportunity.id;

		role4 = new OpportunityContactRole();
		role4.opportunityId = opportunity.id;

		role5 = new OpportunityContactRole();
		role5.opportunityId = opportunity.id;

		System.debug('In Constructor for createNewOpportunity, tempAcc.Id: ' + tempAcc.Id);
		System.debug('In Constructor for createNewOpportunity, opportunity.AccountId: ' + opportunity.AccountId);
	}

	public PageReference step1()
	{
		System.debug('In step1, tempAcc.Id: ' + tempAcc.Id);
		System.debug('In step1, opportunity.AccountId: ' + opportunity.AccountId);
		return Page.newOpportunityStep1;
	}

	public PageReference step2()
	{
		tempAcc = [SELECT Id, Name, countOpenOpportunities__c FROM Account WHERE Id =: opportunity.AccountId];
		// Set the Opportunity name here based on what was set in step1
		if (opportunity.Name == null)
		{
			//Set the opportunity name to a standard name
			opportunity.Name = opportunity.Type + ' ' + opportunity.Service_Type__c + ' Program for ' + tempAcc.Name;
		}

		System.debug('In step2, tempAcc.Id: ' + tempAcc.Id);
		System.debug('In step2, opportunity.AccountId: ' + opportunity.AccountId);

		return Page.newOpportunityStep2;
	}

	public PageReference step3()
	{
		//Set the roles to the opportunity
		if (role1.ContactId != null)
		{
			contact1 = [SELECT Id,Name,Title FROM Contact WHERE Id =: role1.ContactId];
		}

		if (role2.ContactId != null)
		{
			contact2 = [SELECT Id,Name,Title FROM Contact WHERE Id =: role2.ContactId];
		}

		if (role3.ContactId != null)
		{
			contact3 = [SELECT Id,Name,Title FROM Contact WHERE Id =: role3.ContactId];
		}

		if (role4.ContactId != null)
		{
			contact4 = [SELECT Id,Name,Title FROM Contact WHERE Id =: role4.ContactId];
		}

		if (role5.ContactId != null)
		{
			contact5 = [SELECT Id,Name,Title FROM Contact WHERE Id =: role5.ContactId];
		}		

		return Page.newOpportunityStep3;
	}

	// This method cancels the wizard, and returns the user to the 
	// Opportunities tab
	public PageReference cancel()
	{
		PageReference opportunityPage = new ApexPages.StandardController(opportunity).view();
		opportunityPage.setRedirect(true);
		return opportunityPage; 
	}

	// This method performs the final save for all four objects, and
	// then navigates the user to the detail page for the new
	// opportunity.
	public PageReference save()
	{
		opportunity.accountId = tempAcc.id;
		insert opportunity;

		if(role1.ContactId != null)
		{
			role1.opportunityId = opportunity.id;
			insert role1;
		}
		if(role2.ContactId != null)
		{
			role2.opportunityId = opportunity.id;
			insert role2;
		}
		if(role3.ContactId != null)
		{
			role3.opportunityId = opportunity.id;
			insert role3;
		}
		if(role4.ContactId != null)
		{
			role4.opportunityId = opportunity.id;
			insert role4;
		}
		if(role5.ContactId != null)
		{
			role5.opportunityId = opportunity.id;
			insert role5;
		}

		// Finally, send the user to the detail page for 
		// the new opportunity.

		PageReference opptyPage = new ApexPages.StandardController(opportunity).view();
		opptyPage.setRedirect(true);

		return opptyPage;
	}
}

 Here's my class for the custom contact lookup page:

 

public with sharing class CustomContactLookupController
{
	public Contact contact {get;set;} // new contact to create
	public List<Contact> results {get;set;} // search results
	public string searchString {get;set;} // search keyword
	private final Id currentUserId; //logged in user's Id
	private final Account myAcct;
	private final createNewOpportunity myReference;

	public CustomContactLookupController(createNewOpportunity myController) {
		contact = new Contact();
		this.myReference = myController;

		System.debug('myReference.opportunity.AccountId: ' + myReference.opportunity.AccountId);
		System.debug('myReference.tempAcc.Id: ' + myReference.tempAcc.Id);
		System.debug('myReference.tempAcc.Name: ' + myReference.tempAcc.Name);
		
		myAcct = myReference.tempAcc;

		System.debug('myAcct Id: ' + myAcct.Id);
		System.debug('myAcct Name: ' + myAcct.Name);
		//this.myAcct = myController.getTheAccount();
		//System.debug('Does myAcct have an ID now? ' + myAcct.Id);
		//System.debug('Can I access a property on myController? ' + myController.tempAcc.Id);
		currentUserId = UserInfo.getUserId();
	    // get the current search string
	    searchString = System.currentPageReference().getParameters().get('lksrch');
	    runSearch();
	    
	}	

	// performs the keyword search
	public PageReference search()
	{
		runSearch();
		return null;
	}

	// prepare the query and issue the search command
	private void runSearch()
	{
		// TODO prepare query string for complex searches & prevent injections
		results = performSearch(searchString);               
	} 

	// run the search and return the records found. 
	private List<Contact> performSearch(string searchString)
	{
		String soql = 'SELECT id, name FROM Contact';
		if(searchString != '' && searchString != null)
		{
			soql = soql + ' WHERE name LIKE \'%' + searchString + '%\'';
			soql = soql + ' AND OwnerId =: currentUserId';
			soql = soql + ' AND AccountId =: myAcct.Id';
			soql = soql + ' ORDER BY LastViewedDate DESC';
			soql = soql + ' LIMIT 50';
		} else
		{
			soql = soql + ' WHERE OwnerId =: currentUserId';
			soql = soql + ' AND AccountId =: myAcct.Id';
			soql = soql + ' ORDER BY LastViewedDate DESC';
			soql = soql + ' LIMIT 50';
		}
		return database.query(soql); 
	}

	// save the new contact record
	public PageReference saveContact()
	{
		insert contact;
		// reset the contact
		contact = new Contact();
		return null;
	}

	// used by the visualforce page to send the link to the right dom element
	public string getFormTag()
	{
		return System.currentPageReference().getParameters().get('frm');
	}

	// used by the visualforce page to send the link to the right dom element for the text box
	public string getTextBox()
	{
		return System.currentPageReference().getParameters().get('txt');
	}
}

 

And then finally the top of my VF page for the custom contact lookup pop-up window looks like the following:

 

<apex:page controller="createNewOpportunity" extensions="CustomContactLookupController"
title="Search" 
showHeader="false" 
sideBar="false" 
tabStyle="Contact" 
id="pg">

...my VF page stuff...

</apex:page>

 

The error I'm getting currently is the following:

 

Visualforce Error

System.QueryException: Variable does not exist: myAcct.Id

 

Keep in mind that I'm a beginner (both as a developer and with apex) and still learning a lot of these concepts and there is a lot that still isn't completely clear to me. I'm sure it's because I'm missing something very basic in my understanding of how all of this works. However, after extensive Google searching I"m still banging my head on this one. If anyone has a couple of minutes to take a look at this and give me some guidance/direction, I would really appreciate it! 

 

Thank you!

 

 

 

 

I'm in the process of overriding our "new" button functionality for when our users create a new lead. One of the things that I lost (I think) as I was doing this was having the User ID automatically assigned to the Owner ID. I'd like to also allow the user to change this (e.g. they're creating a lead, but need to assign it to someone else) as this situation happens at times.

 

I've done some Google searching to figure out if I can set the value for a field, but I haven't been able to find any examples (poor Google skills, I'm thinking).

 

Could anyone help me with this?

 

This is what I have so far for my page:

 

<apex:page standardController="Lead" tabStyle="Lead" showHeader="true" sidebar="true">

	<apex:form>

		<apex:sectionHeader title="Lead Edit" subtitle="{!if(Lead.Id==null,'New Lead',Lead.Name)}">

			<apex:pageBlock mode="maindetail" id="myLeadInstructions" title="Lead Instructions">
			
				I'll put my Lead Rules information here in standard HTML.

			</apex:pageBlock>

			<apex:pageBlock mode="edit" id="leadEditBlock" title="Lead Edit">

				<apex:pageBlockButtons>
					<apex:commandButton action="{!save}" value="Save"></apex:commandButton>
					<apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton>
				</apex:pageBlockButtons>

				<apex:pageMessages></apex:pageMessages>

				<apex:pageBlockSection id="leadInfoBlock" title="Lead Information">

					<apex:inputField value="{!Lead.OwnerID}"></apex:inputField>
					<apex:inputField value="{!Lead.Phone}"></apex:inputField>

					<apex:pageBlockSectionItem>

						<apex:outputLabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputLabel>

						<apex:outputPanel>

							<apex:inputField value="{!Lead.Salutation}"></apex:inputField>
							<apex:inputField value="{!Lead.FirstName}"></apex:inputField>

						</apex:outputPanel>

					</apex:pageBlockSectionItem>

					<apex:inputField value="{!Lead.MobilePhone}"></apex:inputField>
					<apex:inputField value="{!Lead.LastName}"></apex:inputField>
					<apex:inputField value="{!Lead.Company}"></apex:inputField>
					<apex:inputField value="{!Lead.Email}"></apex:inputField>
					<apex:inputField value="{!Lead.Title}"></apex:inputField>
					<apex:inputField value="{!Lead.Website}"></apex:inputField>
					<apex:inputField value="{!Lead.Leadsource}"></apex:inputField>
					<apex:inputField value="{!Lead.Status}"></apex:inputField>
					<apex:inputField value="{!Lead.Industry}"></apex:inputField>
					<apex:inputField value="{!Lead.NumberOfEmployees}"></apex:inputField>

				</apex:pageBlockSection>				

			</apex:pageBlock>

		</apex:sectionHeader>

	</apex:form>
	
</apex:page>

 Thanks for your help!

I've created a junction object called "OCP"

On object "OCP" I've created two Master-detail relationships, one that points to my custom object "Company Products" and one that points to the standard object "Opportunity". My custom object "Company Products" also has a Master-detail relationship with the standard object "Accounts".

"Company Products" <---Master-detail---- "OCP" ----Master-detail---> "Opportunity"

My sales reps need to be able to create or select "Company Products" records from the Accounts page layout (which I'm doing with standard functionality due to the master-detail relationship Company Products has with Accounts) and from the Opportunity page layout (this is where I need help).

Currently when I add the Company Products related list to the Opportunity page layout I can add all of the fields, but the "New" button is trying to create a New Junction Object record and I need this button to allow our reps to create new, or select existing Company Products records for an Opportunity.

I'm sure I do this by creating a custom button, however the custom button stuff that I have read really does my head in (I'm still a fairly new SFDC admin and am in the early parts of the learning curve).

Could someone explicitly walk me through what I need to do here? I've done extensive google searching to try to find an example, but I couldn't find anything directly applicable to what I'm trying to do (my google skills failed me!).

Thank you!

Hello everyone -

 

I need to create a VF page that I can insert on my Opportunity Detail page layout that will contain custom fields for the Account object. This will allow our sales reps to edit/update these fields when they're working on an opportunity and also allow me to build some vaildation logic on the opportunity page to require that these Account fields are updated before they can move the opporutnity to the next stage in our sales process.

 

I understand that I need to extend the Opporunity controller in order to be able to do this. I've been searching for an example that I could work from (as I'm still learning Apex - only a few hours in), but I haven't been able to find anything.

 

Would anyone here be up to throwing together a quick example of extending the opportunity controller to access custom account fields to help me?

 

I'll also need to extend the Opportunity controller to access fields on some custom objects, but I'm thinking that once I get a good handle on how to do it with the Account object, I'll be able to do it with my custom objects.

 

Thanks for your help!

So this might be a bit of an odd request, but I'm looking for someone that could help guide me as I'm teaching myself Apex and VisualForce development. This person would be a resource for me when I get stuck to help keep me progressing in my proficiency with Apex and Visualforce development. I'm working through the workbooks and guides currently, but I know I'm going to need access to someone that can answer questions for me when I get stuck, or don't quite understand a topic. Sometimes you just need someone that you can talk to vs. reading and re-reading to get the solution.

 

The way I'd like to setup the relationship would be on an hourly basis where this person would bill me for the time used on a weekly/monthly basis as they help me progress in these areas.

 

Please contact me if you're interested.

 

Thanks!

 

- Ken

 

 

 

 

I had someone reach out and offer to help me with some of the Apex trigger work I've been looking at. The first thing they asked for was a login to our SFDC organization. That surprised me as i wasn't expecting that. If this is normal, I just wanted to get some confirmation. And if they do need access, could i just give them access to our sandbox?

 

LIving in a world of too many scams has me a little paranoid and I want to make sure I don't make a mistake.

 

Thanks!

I was hoping I could get some help creating an inline visualforce page on my Opportunity page layout.

 

The purpose of this page would be to display instructions to the sales rep based on the opportunity's current stage. And then when the opportunity stage changes, the content of the inline visual force page would change and display the new instructions for the new stage selected.

 

Example:

 

First opportunity stage = Sales Qualified Lead

 

Inline visualforce page would display static text specific to the Sales Qualified Lead stage. Something like this:

 

1) Make sure you walk them through the standard checklist document (html link to doc on intranet)

2) Make sure you review the ABC document with them (html link to doc on intranet)

 

Then when the sales rep moves the opportunity to the next stage:

 

Second opportunity stage = Needs Analysis

 

The visualforce page's content changes and shows them a new set of instructions based on the Needs Analysis stage. Something like:

 

1) Complete the company overview presentation with them (link to PPT on intranet)

2) Demonstrate our our reporting functionality (link to doc)

 

And then the rest of the opportunity stages would work just like the above, each with specific instructions based on the stage.

 

As the sales rep progresses through our sales process and changes the sales stage they always have instructions on what they're supposed to be doing during that stage of our sales process.

 

I'm brand new to visualforce (watching the introduction to visualforce pages video now - lol) and would be very grateful if someone could give me the basic building blocks to do what I'm trying to do here and then I could take it from there.

 

Thank you!

 

- Ken

I am looking at a possible solution to help enforce that our sales reps add the correct contacts to an opportunity and assign roles to those contacts (as well as identifying who the primary contact is for the opportunity). The scenario would work like the following:

 

For our opportunities we know that we need at least two specific roles (defined in our opportunity contact roles) on every opportunity. I'd like to create two custom true/false fields on the opportunity (one for each role that we need). These fields would be updated by an apex trigger that would set the appropriate field to true when a contact was assigned the appropriate contact role for the opportunity.

 

I would also like to add a custom true/false field that would be updated to true when a contact associated with the opportunity was assigned as the "primary" contact (ensuring that all opportunities by a certain stage have a contact that has been assigned as the primary).

 

I could then have validation rules on those custom opportunity fields that wouldn't allow the opportunity stage to be advanced until the sales rep had identified and associated the required contacts/roles and primary.

 

So the opportunity contact roles that would be "required" would be:

 

  1. Sales leader
  2. Marketing leader

 

And the custom checkbox fields I would define for the Opportunity would be:

 

  1. Sales_Leader_Identified__c
  2. Marketing_Leader_Identified__c
  3. Primary_Assigned__c

I'm very new to the apex trigger world and would really love some help in creating this trigger if anyone is up for the challenge. Thanks for any help or guidance you can give here!

Primary Intelligence (www.primary-intel.com) is seeking an experienced application developer with Salesforce, Force.com, Apex, VisualForce and Triggers experience to join our team and lead the development, integration and maintenance of our force.com applications supporting Sales, Sales Management and Sales Support business processes.

 

This position will become the lead developer of a new, cutting-edge solution we have introduced as part of our solution set. You can review the first version here: Version 1.0

 

Our clients have recognized immense value from the barebones v1.0 product available to them today and Primary Intelligence needs a developer to join our team and take over the development of this key product. We have a robust product roadmap for the next 18 months for this product and now need to find the right person to lead the development efforts for v2.0 and beyond.

 

Local and remote candidates accepted (anywhere in the U.S.or Canada).

 

Review the full details of the opportunity here: Job Description

 

Feel free to contact me with any questions.

 

Ken Allred

kallred@primary-intel.com

 

I'm in the process of overriding our "new" button functionality for when our users create a new lead. One of the things that I lost (I think) as I was doing this was having the User ID automatically assigned to the Owner ID. I'd like to also allow the user to change this (e.g. they're creating a lead, but need to assign it to someone else) as this situation happens at times.

 

I've done some Google searching to figure out if I can set the value for a field, but I haven't been able to find any examples (poor Google skills, I'm thinking).

 

Could anyone help me with this?

 

This is what I have so far for my page:

 

<apex:page standardController="Lead" tabStyle="Lead" showHeader="true" sidebar="true">

	<apex:form>

		<apex:sectionHeader title="Lead Edit" subtitle="{!if(Lead.Id==null,'New Lead',Lead.Name)}">

			<apex:pageBlock mode="maindetail" id="myLeadInstructions" title="Lead Instructions">
			
				I'll put my Lead Rules information here in standard HTML.

			</apex:pageBlock>

			<apex:pageBlock mode="edit" id="leadEditBlock" title="Lead Edit">

				<apex:pageBlockButtons>
					<apex:commandButton action="{!save}" value="Save"></apex:commandButton>
					<apex:commandButton action="{!cancel}" value="Cancel"></apex:commandButton>
				</apex:pageBlockButtons>

				<apex:pageMessages></apex:pageMessages>

				<apex:pageBlockSection id="leadInfoBlock" title="Lead Information">

					<apex:inputField value="{!Lead.OwnerID}"></apex:inputField>
					<apex:inputField value="{!Lead.Phone}"></apex:inputField>

					<apex:pageBlockSectionItem>

						<apex:outputLabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputLabel>

						<apex:outputPanel>

							<apex:inputField value="{!Lead.Salutation}"></apex:inputField>
							<apex:inputField value="{!Lead.FirstName}"></apex:inputField>

						</apex:outputPanel>

					</apex:pageBlockSectionItem>

					<apex:inputField value="{!Lead.MobilePhone}"></apex:inputField>
					<apex:inputField value="{!Lead.LastName}"></apex:inputField>
					<apex:inputField value="{!Lead.Company}"></apex:inputField>
					<apex:inputField value="{!Lead.Email}"></apex:inputField>
					<apex:inputField value="{!Lead.Title}"></apex:inputField>
					<apex:inputField value="{!Lead.Website}"></apex:inputField>
					<apex:inputField value="{!Lead.Leadsource}"></apex:inputField>
					<apex:inputField value="{!Lead.Status}"></apex:inputField>
					<apex:inputField value="{!Lead.Industry}"></apex:inputField>
					<apex:inputField value="{!Lead.NumberOfEmployees}"></apex:inputField>

				</apex:pageBlockSection>				

			</apex:pageBlock>

		</apex:sectionHeader>

	</apex:form>
	
</apex:page>

 Thanks for your help!

Hello everyone -

 

I need to create a VF page that I can insert on my Opportunity Detail page layout that will contain custom fields for the Account object. This will allow our sales reps to edit/update these fields when they're working on an opportunity and also allow me to build some vaildation logic on the opportunity page to require that these Account fields are updated before they can move the opporutnity to the next stage in our sales process.

 

I understand that I need to extend the Opporunity controller in order to be able to do this. I've been searching for an example that I could work from (as I'm still learning Apex - only a few hours in), but I haven't been able to find anything.

 

Would anyone here be up to throwing together a quick example of extending the opportunity controller to access custom account fields to help me?

 

I'll also need to extend the Opportunity controller to access fields on some custom objects, but I'm thinking that once I get a good handle on how to do it with the Account object, I'll be able to do it with my custom objects.

 

Thanks for your help!

So this might be a bit of an odd request, but I'm looking for someone that could help guide me as I'm teaching myself Apex and VisualForce development. This person would be a resource for me when I get stuck to help keep me progressing in my proficiency with Apex and Visualforce development. I'm working through the workbooks and guides currently, but I know I'm going to need access to someone that can answer questions for me when I get stuck, or don't quite understand a topic. Sometimes you just need someone that you can talk to vs. reading and re-reading to get the solution.

 

The way I'd like to setup the relationship would be on an hourly basis where this person would bill me for the time used on a weekly/monthly basis as they help me progress in these areas.

 

Please contact me if you're interested.

 

Thanks!

 

- Ken

 

 

 

 

I had someone reach out and offer to help me with some of the Apex trigger work I've been looking at. The first thing they asked for was a login to our SFDC organization. That surprised me as i wasn't expecting that. If this is normal, I just wanted to get some confirmation. And if they do need access, could i just give them access to our sandbox?

 

LIving in a world of too many scams has me a little paranoid and I want to make sure I don't make a mistake.

 

Thanks!