• dmote
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 17
    Replies

Hi,

 

I created a VF page and custom controller.  I would like to add a button on the Account Page to go to the VF Page.  When I try to create the button, I select detail page button and the content source is visualforce page, but there is nothing in the content drop down box.

 

I don't know what I am doing wrong.  Is there a setting somewhere I need to change?  I am doing this in my sandbox on Enterprise Edition.

 

Thanks,

  • September 23, 2010
  • Like
  • 0

I am trying to create a test for my VF Page.  Currently, I have 38% coverage.  I have methods in my controller that I though was covered by my test, but apparently isn't.  I am really just winging it.

 

Any suggestions would be appreciated.

 

Here is my controller:

 

 

public class newOpportunityController {

    public PageReference step2() {
      //pageRef.setRedirect(true);       
      //pageRef.setRedirect(false);
      return page.davidPage2;

    }
    

    
   Account account;
   Contact myContact;
   public List<Contact> contact{get;set;}
   public String selectedContact{get; set;}
   public List<SelectOption> contactList{get;set;}
   public Contact contacts{get; set;} 
   public Opportunity opportunity {get; set;}
  /*
    This will create standard getters and setter like the following
    public Opportunity getOpportunity(){
       return this.opportunity;
    }
    public void setOpportunity(Opportunity value){
        this.opportunity = value;
    }

   You need only setter method to accomplish the task like the "setOpportunity" method,
   if you decide to keep the getter you have already coded below.
  */
   OpportunityContactRole role;
   Quote q;


   
   
   public newOpportunityController()
   {      
    opportunity = new Opportunity();
    if (contactList == null)
    {
        List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
        contactList = new List<SelectOption>();
        for (Contact c : contactee)
        {
            contactList.add(new SelectOption( c.id, c.name ));
        }
     }   
   }
   
   
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
      public Contact getMyContact() {
        return [select id, Name from Contact
        where id = :selectedContact];
    }
    
//not needed.
/*      
 public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;
   }

*/

 public OpportunityContactRole getRole() {
      if(role == null) role = new OpportunityContactRole();
      return role;
   }

 public Quote getQ() {
      if(q == null) q = new Quote();
      return q;
   }

   public PageReference test()
   {
    if (selectedContact!=null)
    {
       contacts=[select id, firstName,lastName,email from Contact where id = :selectedContact];
    }
    return null;
   }

   public PageReference save() {

      // Create the opportunity. Before inserting, create   
    
      // another relationship with the account.  
    
      opportunity.accountId = ApexPages.currentPage().getParameters().get('id');
      insert opportunity;

      // Create the junction contact role between the opportunity  
    
      // and the contact.  
    
      role.opportunityId = opportunity.id;
      role.contactId = selectedContact;
      insert role;
      
  //    q.account = ApexPages.currentPage().getParameters().get('id');
      q.name = q.name;
      q.opportunityId = opportunity.id;
      q.contactId = selectedContact;
  //    q.amount = opportunity.amount;
      insert q;
       
      PageReference opptyPage = new ApexPages.StandardController(q).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }



}

 

and my test class:

 

 

 

public class thecontrollerTests {
public static testMethod void testnewOpportunityController() {
PageReference pageRef = Page.success;
Test.setCurrentPage(pageRef);
Opportunity testOpp; // = new opportunity();

Quote testQ = new quote();
OpportunityContactRole testRole; // = new opportunityContactRole();
newOpportunityController controller = new newOpportunityController();
String nextPage = controller.save().getURL();
// Verify that page fails without parameters
System.assertEquals('/apex/failure?error=noParam', nextPage);
// Add parameters to page URL
ApexPages.currentPage().getParameters().put('id', '001S000000CmJg7');
controller.getAccount();
//controller.getOpportunity();
controller.getRole();
// Instantiate a new controller with all parameters in the page
controller = new newOpportunityController();
testOpp.name = 'testClassOpp';
testOpp.stageName = 'Prorosal/Price Quote';
testRole.role = 'Decision Maker';
testQ.name = 'testQuote';
controller.save();

// Verify that the success page displays
System.assertEquals('/apex/success', nextPage);

}}

 

 

Even just a nudge in the right direction would be appreciated!

 

Thanks,

David

  • September 17, 2010
  • Like
  • 0

Good Morning All,

 

I am trying to create an Opportunity Wizard where a user clciks on a button from a specific account and is taken to a VF Page where they select a contact associated with the account from a drop down list and then enters the new opportunity info.  They then click onNext which takes them to a new page and displays back the infor entered.  I am able to dsiplay back the Account and contact info, but the opportunity info is getting lost.

 

Any suggestions?

 

VF Page 1 Code

<apex:page controller="newOpportunityController" tabStyle="Opportunity">
   <apex:pageMessages id="msgs"/>
   <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/>
   <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
         <apex:pageBlockButtons >
            <apex:commandButton action="{!step2}" value="Next"/>
         </apex:pageBlockButtons>
         <apex:pageBlockSection title="Account Information">
            <!-- Within a pageBlockSection, inputFields always display with their
               corresponding output label. -->  
            You are viewing the {!account.name} account. <p/>
         </apex:pageBlockSection>

         <apex:pageBlockSection title="Contacts">
            <apex:selectList value="{!selectedContact}" multiselect="false">
               <apex:selectOptions value="{!contactList}"/>
            </apex:selectList>
         </apex:pageBlockSection>
      
         <apex:pageBlockSection title="Opportunity Information">
            <apex:inputField id="opportunityName" value="{!opportunity.name}"/>
            <apex:inputField id="opportunityAmount" value="{!opportunity.amount}"/>
            <apex:inputField id="opportunityCloseDate" value="{!opportunity.closeDate}"/>
            <apex:inputField id="opportunityStageName" value="{!opportunity.stageName}"/>
            <apex:inputField id="contactRole" value="{!role.role}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>
</apex:page>

Controller Code

public class newOpportunityController {

    public PageReference step2() {
      PageReference pageRef = new PageReference('https://c.cs1.visual.force.com/apex/davidpage2?id=' + ApexPages.currentPage().getParameters().get('id')+ '&cid=' + selectedContact);
      pageRef.setRedirect(true);
     
      return pageRef;

    }


    
   Account account;
   Contact myContact;
   public List<Contact> contact{get;set;}
   public String selectedContact{get; set;}
   public List<SelectOption> contactList{get;set;}
   public Contact contacts{get; set;}
   Opportunity opportunity;
   OpportunityContactRole role;


   
   
   public newOpportunityController()
   {
    if (contactList == null)
    {
        List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
        contactList = new List<SelectOption>();
        for (Contact c : contactee)
        {
            contactList.add(new SelectOption( c.id, c.name ));
        }
     }   
   }
   
   
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
      public Contact getMyContact() {
        return [select id, Name from Contact
        where id = :ApexPages.currentPage().getParameters().get('cid')];
    }
    
       public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;
   }

   public OpportunityContactRole getRole() {
      if(role == null) role = new OpportunityContactRole();
      return role;
   }


   public PageReference test()
   {
    if (selectedContact!=null)
    {
       contacts=[select id, firstName,lastName,email from Contact where id = :selectedContact];
    }
    return null;
   }


}

VF Page 2

<apex:page controller="newOpportunityController" tabStyle="Opportunity">
  <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/>
  <apex:form >
    <apex:pageBlock title="Confirmation">

      <apex:pageBlockSection title="Account Information">
        <apex:outputField value="{!account.name}"/>
        <apex:outputField value="{!account.site}"/>
      </apex:pageBlockSection>

            <apex:pageBlockSection title="Opportunity Information">
        <apex:outputField value="{!opportunity.name}"/>
        <apex:outputField value="{!opportunity.amount}"/>
        <apex:outputField value="{!opportunity.closeDate}"/>
      </apex:pageBlockSection>

      <apex:pageBlockSection title="Contact Information">
         <apex:outputField value="{!myContact.name}"/>
         <apex:outputField value="{!role.role}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

Thanks for any help!

David



  • September 13, 2010
  • Like
  • 0

I am trying to create a VF page where I show all contacts related to an account.  Once the contacted is selected and the user presses go, I want to display the name of the contact.  I can get it to display the id, but I can't figure out how to access the other contact fields.  Does this have to do with returning the contact id as a string?  Can I return the id as a contact?  I have been trying to do this for a while, and I can't figure it out.  I have also read through a ton of docs, but can only make it work when multiselect = true.  I want to do this when multiselect = false. 

 

Here is my code. 

 

Thanks for your help.

 

Apex Page:

 

<apex:page controller="newOpportunityController" tabStyle="Opportunity">
  <apex:pageMessages id="msgs"/>
  <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/>
    <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
      <apex:pageBlockSection title="Account Information">
                        
        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->  
              You are viewing the {!account.name} account. <p/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Contacts">
         <apex:selectList value="{!selectedContact}" multiselect="false">
            <apex:selectOptions value="{!contact}"/>
         </apex:selectList>
      </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:commandButton value="Go" action="{!test}" rerender="out, msgs" status="status"/>
  </apex:form>
  
    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    <p>You have selected:</p>
                    <apex:dataList value="{!selectedContact}" var="c">{!c.name}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
    
</apex:page>

 

Controller:

 

public class newOpportunityController {

    public String getContacts() {
        return null;
    }


   Account account;
   Contact contact;

   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public String selectedContact;
    
    public String getSelectedContact()
    {
        return selectedContact;
    }
    
    public void setSelectedContact(String sel)
    {
        selectedContact=sel;
    }
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
            contactList.add(new SelectOption( c.id, c.name ));
        }
    }
    return contactList;
    }
 
    Contact contacts;
//    public Contact contacts() {get;set;}

   public PageReference test()
   {
    // blank out any earlier contact details
//    contact= new Contact;
    if (null!=selectedContact)
    {
       contacts=[select id, name from Contact where id = :selectedContact];
    }
    return null;
   }


}

 

 

 

  • August 30, 2010
  • Like
  • 0

Ok...here is my problem.  I want to have a user select a contact related to an account from a Select List.  My understanding is that the selected option is returned as a string, which in this case is the contact ID.  How, in the controller do I then reference the contact.  I know how to reference the contact in the Apex Page, but I want to be able to see the contact information on my next Apex Page and save the contact to a new opportunity that I am creating next.

 

 

public class testController {
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
   Contact contact;
    
    public String selectedContact {get;set;}
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name,  contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
           contactList.add(new SelectOption(c.id,c.name));
        }
    }
    return contactList;
    }

  public PageReference step2() {
     string acctid = ApexPages.currentPage().getParameters().get('id');
     PageReference newPage = new pageReference('/apex/newQuote2?id=' + acctid);
     return newPage.setRedirect(true);

   }
   


}

 

 

Thanks for any and all assistance.

 

David

  • August 23, 2010
  • Like
  • 0

I have multiple Lead Remarks that need to get updated when a lead is converted.  Below is my code, however when it triggers, it only updates the first lead remark.  I need it to update all of them.  I am guessing that I need a for loop in here somewhere, but not sure where.

 

 

trigger UpdateCustomeObject_Trigger on Lead (before update) {
//This trigger will associate a Custom Object record with the contact and opportunity associated to the
//lead after it has been converted.
//The Custom Object is associated to an opportunity only if an opportunity record exist on the Lead.
    for (Integer i = 0; i < Trigger.new.size(); i++){
        if (Trigger.new[i].IsConverted == true && Trigger.old[i].isConverted == false){
            Set<Id> leadIds = new Set<Id>();
            for (Lead lead : Trigger.new)
                leadIds.add(lead.Id);
           
            Map<Id, Lead_Remark__c> entries = new Map<Id, Lead_Remark__c>([select Contact__c, Lead__c from Lead_Remark__c where lead__c in :leadIds]);       
            if(!Trigger.new.isEmpty()) {
                for (Lead lead : Trigger.new)  {
                    for (Lead_remark__c Lead_Remark : entries.values()) {
                        if (Lead_Remark.Lead__c == lead.Id) {
                            Lead_Remark.contact__c = lead.ConvertedContactId;
                            update Lead_Remark;
                            break;
                        }
                    }
                }
            }
        }
    }

}

 

Thanks in advance,

David

  • May 19, 2010
  • Like
  • 0

I have created a custom object attached to a lead, called a lead remark.  I also have an object called remark attached to contact.  Is it possible to map all of the lead remarks to move to contact remarks during the lead conversion process?

 

Thanks in advance!

David

Message Edited by dmote on 11-10-2009 11:14 AM
  • November 10, 2009
  • Like
  • 0

Hi,

 

I created a VF page and custom controller.  I would like to add a button on the Account Page to go to the VF Page.  When I try to create the button, I select detail page button and the content source is visualforce page, but there is nothing in the content drop down box.

 

I don't know what I am doing wrong.  Is there a setting somewhere I need to change?  I am doing this in my sandbox on Enterprise Edition.

 

Thanks,

  • September 23, 2010
  • Like
  • 0

I am trying to create a test for my VF Page.  Currently, I have 38% coverage.  I have methods in my controller that I though was covered by my test, but apparently isn't.  I am really just winging it.

 

Any suggestions would be appreciated.

 

Here is my controller:

 

 

public class newOpportunityController {

    public PageReference step2() {
      //pageRef.setRedirect(true);       
      //pageRef.setRedirect(false);
      return page.davidPage2;

    }
    

    
   Account account;
   Contact myContact;
   public List<Contact> contact{get;set;}
   public String selectedContact{get; set;}
   public List<SelectOption> contactList{get;set;}
   public Contact contacts{get; set;} 
   public Opportunity opportunity {get; set;}
  /*
    This will create standard getters and setter like the following
    public Opportunity getOpportunity(){
       return this.opportunity;
    }
    public void setOpportunity(Opportunity value){
        this.opportunity = value;
    }

   You need only setter method to accomplish the task like the "setOpportunity" method,
   if you decide to keep the getter you have already coded below.
  */
   OpportunityContactRole role;
   Quote q;


   
   
   public newOpportunityController()
   {      
    opportunity = new Opportunity();
    if (contactList == null)
    {
        List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
        contactList = new List<SelectOption>();
        for (Contact c : contactee)
        {
            contactList.add(new SelectOption( c.id, c.name ));
        }
     }   
   }
   
   
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
      public Contact getMyContact() {
        return [select id, Name from Contact
        where id = :selectedContact];
    }
    
//not needed.
/*      
 public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;
   }

*/

 public OpportunityContactRole getRole() {
      if(role == null) role = new OpportunityContactRole();
      return role;
   }

 public Quote getQ() {
      if(q == null) q = new Quote();
      return q;
   }

   public PageReference test()
   {
    if (selectedContact!=null)
    {
       contacts=[select id, firstName,lastName,email from Contact where id = :selectedContact];
    }
    return null;
   }

   public PageReference save() {

      // Create the opportunity. Before inserting, create   
    
      // another relationship with the account.  
    
      opportunity.accountId = ApexPages.currentPage().getParameters().get('id');
      insert opportunity;

      // Create the junction contact role between the opportunity  
    
      // and the contact.  
    
      role.opportunityId = opportunity.id;
      role.contactId = selectedContact;
      insert role;
      
  //    q.account = ApexPages.currentPage().getParameters().get('id');
      q.name = q.name;
      q.opportunityId = opportunity.id;
      q.contactId = selectedContact;
  //    q.amount = opportunity.amount;
      insert q;
       
      PageReference opptyPage = new ApexPages.StandardController(q).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }



}

 

and my test class:

 

 

 

public class thecontrollerTests {
public static testMethod void testnewOpportunityController() {
PageReference pageRef = Page.success;
Test.setCurrentPage(pageRef);
Opportunity testOpp; // = new opportunity();

Quote testQ = new quote();
OpportunityContactRole testRole; // = new opportunityContactRole();
newOpportunityController controller = new newOpportunityController();
String nextPage = controller.save().getURL();
// Verify that page fails without parameters
System.assertEquals('/apex/failure?error=noParam', nextPage);
// Add parameters to page URL
ApexPages.currentPage().getParameters().put('id', '001S000000CmJg7');
controller.getAccount();
//controller.getOpportunity();
controller.getRole();
// Instantiate a new controller with all parameters in the page
controller = new newOpportunityController();
testOpp.name = 'testClassOpp';
testOpp.stageName = 'Prorosal/Price Quote';
testRole.role = 'Decision Maker';
testQ.name = 'testQuote';
controller.save();

// Verify that the success page displays
System.assertEquals('/apex/success', nextPage);

}}

 

 

Even just a nudge in the right direction would be appreciated!

 

Thanks,

David

  • September 17, 2010
  • Like
  • 0

Good Morning All,

 

I am trying to create an Opportunity Wizard where a user clciks on a button from a specific account and is taken to a VF Page where they select a contact associated with the account from a drop down list and then enters the new opportunity info.  They then click onNext which takes them to a new page and displays back the infor entered.  I am able to dsiplay back the Account and contact info, but the opportunity info is getting lost.

 

Any suggestions?

 

VF Page 1 Code

<apex:page controller="newOpportunityController" tabStyle="Opportunity">
   <apex:pageMessages id="msgs"/>
   <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/>
   <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
         <apex:pageBlockButtons >
            <apex:commandButton action="{!step2}" value="Next"/>
         </apex:pageBlockButtons>
         <apex:pageBlockSection title="Account Information">
            <!-- Within a pageBlockSection, inputFields always display with their
               corresponding output label. -->  
            You are viewing the {!account.name} account. <p/>
         </apex:pageBlockSection>

         <apex:pageBlockSection title="Contacts">
            <apex:selectList value="{!selectedContact}" multiselect="false">
               <apex:selectOptions value="{!contactList}"/>
            </apex:selectList>
         </apex:pageBlockSection>
      
         <apex:pageBlockSection title="Opportunity Information">
            <apex:inputField id="opportunityName" value="{!opportunity.name}"/>
            <apex:inputField id="opportunityAmount" value="{!opportunity.amount}"/>
            <apex:inputField id="opportunityCloseDate" value="{!opportunity.closeDate}"/>
            <apex:inputField id="opportunityStageName" value="{!opportunity.stageName}"/>
            <apex:inputField id="contactRole" value="{!role.role}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>
</apex:page>

Controller Code

public class newOpportunityController {

    public PageReference step2() {
      PageReference pageRef = new PageReference('https://c.cs1.visual.force.com/apex/davidpage2?id=' + ApexPages.currentPage().getParameters().get('id')+ '&cid=' + selectedContact);
      pageRef.setRedirect(true);
     
      return pageRef;

    }


    
   Account account;
   Contact myContact;
   public List<Contact> contact{get;set;}
   public String selectedContact{get; set;}
   public List<SelectOption> contactList{get;set;}
   public Contact contacts{get; set;}
   Opportunity opportunity;
   OpportunityContactRole role;


   
   
   public newOpportunityController()
   {
    if (contactList == null)
    {
        List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
        contactList = new List<SelectOption>();
        for (Contact c : contactee)
        {
            contactList.add(new SelectOption( c.id, c.name ));
        }
     }   
   }
   
   
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
      public Contact getMyContact() {
        return [select id, Name from Contact
        where id = :ApexPages.currentPage().getParameters().get('cid')];
    }
    
       public Opportunity getOpportunity() {
      if(opportunity == null) opportunity = new Opportunity();
      return opportunity;
   }

   public OpportunityContactRole getRole() {
      if(role == null) role = new OpportunityContactRole();
      return role;
   }


   public PageReference test()
   {
    if (selectedContact!=null)
    {
       contacts=[select id, firstName,lastName,email from Contact where id = :selectedContact];
    }
    return null;
   }


}

VF Page 2

<apex:page controller="newOpportunityController" tabStyle="Opportunity">
  <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/>
  <apex:form >
    <apex:pageBlock title="Confirmation">

      <apex:pageBlockSection title="Account Information">
        <apex:outputField value="{!account.name}"/>
        <apex:outputField value="{!account.site}"/>
      </apex:pageBlockSection>

            <apex:pageBlockSection title="Opportunity Information">
        <apex:outputField value="{!opportunity.name}"/>
        <apex:outputField value="{!opportunity.amount}"/>
        <apex:outputField value="{!opportunity.closeDate}"/>
      </apex:pageBlockSection>

      <apex:pageBlockSection title="Contact Information">
         <apex:outputField value="{!myContact.name}"/>
         <apex:outputField value="{!role.role}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

Thanks for any help!

David



  • September 13, 2010
  • Like
  • 0

I am trying to create a VF page where I show all contacts related to an account.  Once the contacted is selected and the user presses go, I want to display the name of the contact.  I can get it to display the id, but I can't figure out how to access the other contact fields.  Does this have to do with returning the contact id as a string?  Can I return the id as a contact?  I have been trying to do this for a while, and I can't figure it out.  I have also read through a ton of docs, but can only make it work when multiselect = true.  I want to do this when multiselect = false. 

 

Here is my code. 

 

Thanks for your help.

 

Apex Page:

 

<apex:page controller="newOpportunityController" tabStyle="Opportunity">
  <apex:pageMessages id="msgs"/>
  <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/>
    <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
      <apex:pageBlockSection title="Account Information">
                        
        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->  
              You are viewing the {!account.name} account. <p/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Contacts">
         <apex:selectList value="{!selectedContact}" multiselect="false">
            <apex:selectOptions value="{!contact}"/>
         </apex:selectList>
      </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:commandButton value="Go" action="{!test}" rerender="out, msgs" status="status"/>
  </apex:form>
  
    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    <p>You have selected:</p>
                    <apex:dataList value="{!selectedContact}" var="c">{!c.name}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
    
</apex:page>

 

Controller:

 

public class newOpportunityController {

    public String getContacts() {
        return null;
    }


   Account account;
   Contact contact;

   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public String selectedContact;
    
    public String getSelectedContact()
    {
        return selectedContact;
    }
    
    public void setSelectedContact(String sel)
    {
        selectedContact=sel;
    }
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
            contactList.add(new SelectOption( c.id, c.name ));
        }
    }
    return contactList;
    }
 
    Contact contacts;
//    public Contact contacts() {get;set;}

   public PageReference test()
   {
    // blank out any earlier contact details
//    contact= new Contact;
    if (null!=selectedContact)
    {
       contacts=[select id, name from Contact where id = :selectedContact];
    }
    return null;
   }


}

 

 

 

  • August 30, 2010
  • Like
  • 0

Ok...here is my problem.  I want to have a user select a contact related to an account from a Select List.  My understanding is that the selected option is returned as a string, which in this case is the contact ID.  How, in the controller do I then reference the contact.  I know how to reference the contact in the Apex Page, but I want to be able to see the contact information on my next Apex Page and save the contact to a new opportunity that I am creating next.

 

 

public class testController {
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
   Contact contact;
    
    public String selectedContact {get;set;}
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name,  contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
           contactList.add(new SelectOption(c.id,c.name));
        }
    }
    return contactList;
    }

  public PageReference step2() {
     string acctid = ApexPages.currentPage().getParameters().get('id');
     PageReference newPage = new pageReference('/apex/newQuote2?id=' + acctid);
     return newPage.setRedirect(true);

   }
   


}

 

 

Thanks for any and all assistance.

 

David

  • August 23, 2010
  • Like
  • 0

Hi,

 

I have been reading through lots of posts, but I cannot figure out the solution to my problem.

 

I am trying to create a VF page from an account that lists all contacts associated with the account.  The user should be able to select a contact and the contact is displayed.

 

I am able to display all the contacts, but not select one.

 

VF Page:

 

 

<apex:page controller="newOpportunityController2" tabStyle="Opportunity">
  <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/>
    <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
      <apex:pageBlockSection title="Account Information">
                        
        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->  
              You are viewing the {!account.name} account. <p/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Contacts">
         <apex:selectList value="{!selectedContact}" multiselect="true">
            <apex:selectOptions value="{!contact}"/>
         </apex:selectList>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
  
    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel>
                    <p>You have selected:</p>
                    <apex:dataList value="{!selectedContact}" var="c">a:{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
    
</apex:page>

 

 

My Controller:

 

 

public class newOpportunityController {

   Account account;
   Contact contact;

   public Account getAccount() {
        if(account == null) account = new Account();
      return account;

   } 
    public String selectedContact {get;set;}
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
            contactList.add(new SelectOption( c.id, c.name ));
        }
    }
    return contactList;
    }
 
//    String[] selectedContact = new String[]{};
 
     public void setContact(String[] selectedContact) {
            this.selectedContact = selectedContact;
        }

     public String[] getSelectedContact() {
            return selectedContact;
        }
            

   
   
   

}

 

 

I am pretty sure my problem is with my gets and set, but I can't figure it out and am getting really confused and frustrated!

 

Thanks in advance for any help.

 

David

  • August 09, 2010
  • Like
  • 0

Help!

 

I created the following VF pages along with the custom controller based on the example from the SFDC cookbook (almost word for word) but I have no idea how to promote to production since I have no idea how to write the unit test to validate the coverage (only at 51%).  Any help would be appreciated.

 

Page 1 of 3

<apex:page controller="newDonationController"tabStyle="Opportunity">

<apex:sectionHeader title="NewCustomerOpportunity"subtitle="Step1of3"/>

<apex:form >

<apex:pageBlock title="CustomerInformation">

<apex:facet name="footer">

<apex:commandButton action="{!step2}"value="Next"styleClass="btn"/>

</apex:facet>

 

<apex:pageBlockSection title="AccountInformation">

<apex:panelGrid columns="2">

<apex:outputLabel value="Account Name"for="accountName"/>

<apex:inputField id="accountName"value="{!account.name}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

<apex:pageBlockSection title="ContactInformation">

<apex:panelGrid columns="2">

<apex:outputLabel value="First Name"for="contactFirstName"/>

<apex:inputField id="contactFirstName"value="{!contact.firstName}"/>

<apex:outputLabel value="Last Name"for="contactLastName"/>

<apex:inputField id="contactLastName"value="{!contact.lastName}"/>

<apex:outputLabel value="Phone"for="contactPhone"/>

<apex:inputField id="contactPhone"value="{!contact.phone}"/>

<apex:outputLabel value="Email"for="contactEmail"/>

<apex:inputField id="contactEmail"value="{!contact.email}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

</apex:pageBlock>

</apex:form>

</apex:page>

Page 2 of 3

<apex:page controller="newDonationController"

tabStyle="Opportunity">

<apex:sectionHeader title="NewCustomerOpportunity"

subtitle="Step2of3"/>

<apex:form>

<apex:pageBlock title="Donation Information">

<apex:facet name="footer">

<apex:outputPanel>

<apex:commandButton action="{!step1}" value="Previous"

styleClass="btn"/>

<apex:commandButton action="{!step3}" value="Next"

styleClass="btn"/>

</apex:outputPanel>

</apex:facet>

 

<apex:pageBlockSection title="Donation Information">

<apex:panelGrid columns="2">

<apex:outputLabel value="Donation Name"

for="opportunityName"/>

<apex:inputField id="opportunityName"

value="{!opportunity.name}"/>

<apex:outputLabel value="Amount"

for="opportunityAmount"/>

<apex:inputField id="opportunityAmount"

value="{!opportunity.amount}"/>

<apex:outputLabel value="Close Date"

for="opportunityCloseDate"/>

<apex:inputField id="opportunityCloseDate"

value="{!opportunity.closeDate}"/>

<apex:outputLabel value="Type"

for="opportunityType"/>

<apex:inputField id="opportunityType"

value="{!opportunity.type}"/>

<apex:outputLabel value="Stage"

for="opportunityStageName"/>

<apex:inputField id="opportunityStageName"

value="{!opportunity.stageName}"/>

<apex:outputLabel value="Payment Type"

for="opportunityPaymentType"/>

<apex:inputField id="opportunityPaymentType"

value="{!opportunity.NFG__Payment_Type__c}"/>

<apex:outputLabel value="Check Date"

for="opportunityCheckDate"/>

<apex:inputField id="opportunityCheckDate"

value="{!opportunity.Check_Date__c}"/>

<apex:outputLabel value="Check #"

for="opportunityCheckNo"/>

<apex:inputField id="opportunityCheckNo"

value="{!opportunity.Check_Number__c}"/>

<apex:outputLabel value="Deposit Date"

for="opportunityDepositDate"/>

<apex:inputField id="opportunityDepositDate"

value="{!opportunity.Bank_Deposit_Date__c}"/>

<apex:outputLabel value="Primary Campaign"

for="opportunityCampaign"/>

<apex:inputField id="opportunityCampaign"

value="{!opportunity.CampaignId}"/>

<apex:outputLabel value="Internet Source"

for="opportunityInternetSource"/>

<apex:inputField id="opportunityInternetSource"

value="{!opportunity.NFG__Internet_Donation_Source__c}"/>

<apex:outputLabel value="Program Desingation"

for="opportunityProgram"/>

<apex:inputField id="opportunityProgram"

value="{!opportunity.Program_Designation__c}"/>

<apex:outputLabel value="Contact Role: {!contact.firstName} {!contact.lastName}"

for="contactRole"/><apex:inputField id="contactRole"

value="{!role.role}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

</apex:pageBlock>

</apex:form>

</apex:page>

Page 3 of 3

<apex:page controller="newDonationController"

tabStyle="Opportunity">

<apex:sectionHeader title="NewCustomerOpportunity"

subtitle="Step3of3"/>

<apex:form>

<apex:pageBlock title="Confirmation">

<apex:facet name="footer">

<apex:outputPanel >

<apex:commandButton action="{!step2}"

value="Previous"styleClass="btn"/>

<apex:commandButton action="{!save}"

value="Save"styleClass="btn"/>

</apex:outputPanel>

</apex:facet>

 

<apex:pageBlockSection title="Account Information">

<apex:panelGrid columns="2">

<apex:outputText value="Account Name:"/>

<apex:outputText value="{!account.name}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

<apex:pageBlockSection title="Contact Information">

<apex:panelGrid columns="2">

<apex:outputText value="First Name:"/>

<apex:outputText value="{!contact.firstName}"/>

<apex:outputText value="Last Name:"/>

<apex:outputText value="{!contact.lastName}"/>

<apex:outputText value="Phone:"/>

<apex:outputText value="{!contact.phone}"/>

<apex:outputText value="Email:"/>

<apex:outputText value="{!contact.email}"/>

<apex:outputText value="Role"/>

<apex:outputText value="{!role.role}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

<apex:pageBlockSection title="Donation Information">

<apex:panelGrid columns="2">

<apex:outputText value="Donation Name:"/>

<apex:outputText value="{!opportunity.name}"/>

<apex:outputText value="Amount:"/>

<apex:outputText value="{!opportunity.amount}"/>

<apex:outputText value="Type:"/>

<apex:outputText value="{!opportunity.type}"/>

<apex:outputText value="Close Date:"/>

<apex:outputText value="{!opportunity.closeDate}"/>

<apex:outputText value="Stage:"/>

<apex:outputText value="{!opportunity.stagename}"/>

<apex:outputText value="Payment Type:"/>

<apex:outputText value="{!opportunity.NFG__Payment_Type__c}"/>

<apex:outputText value="Check Date:"/>

<apex:outputText value="{!opportunity.Check_Date__c}"/>

<apex:outputText value="Check #:"/>

<apex:outputText value="{!opportunity.Check_Number__c}"/>

<apex:outputText value="Check Deposit Date:"/>

<apex:outputText value="{!opportunity.Bank_Deposit_Date__c}"/>

<apex:outputText value="Primary Campaign:"/>

<apex:outputText value="{!opportunity.campaignid}"/>

<apex:outputText value="Internet Source:"/>

<apex:outputText value="{!opportunity.NFG__Internet_Donation_Source__c}"/>

<apex:outputText value="Program Designation:"/>

<apex:outputText value="{!opportunity.Program_Designation__c}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

</apex:pageBlock>

</apex:form>

</apex:page>

public class newDonationController {

Account account;

Contact contact;

Opportunity opportunity;

OpportunityContactRole role;

Campaign campaign;

 

public Account getAccount() {

if(account == null)

return account;

}

public Contact getContact() {

if(contact == null) contact = new Contact();

return contact;

}

public Opportunity getOpportunity() {

if(opportunity == null) opportunity = new Opportunity();

return opportunity;

}

public OpportunityContactRole getRole() {

if(role == null) role = new OpportunityContactRole();

return role;

}

public PageReference step1() {

return Page.DonationStep1;

}

public PageReference step2() {

return Page.DonationStep2;

}

public PageReference step3() {

return Page.DonationStep3;

}

public PageReference save() {

account.phone = contact.phone;

account.NFG__Email__c = contact.email;

insert account;

 

contact.accountId = account.id;

insert contact;

 

opportunity.accountId = account.id;

insert opportunity;

 

role.opportunityId = opportunity.id;

role.contactId = contact.id;

insert role;

 

PageReference donationPage = new PageReference('/' + opportunity.id);

donationPage.setRedirect(true);return donationPage;

}

}

 

Message Edited by pacstrats on 03-30-2010 05:31 PM

Hi,

 

I have a custom object and I need to establish "Master-Detail Relationship" with "Lead" object.

 

I don't find the LEAD populated in the "Related To"  picklist where I have to select the Parent Object.

 

All other standard Objects like Account, Contact, Opportunity are populated in the list EXCEPT "LEAD".

 

I am stuck with that and could not find the reason. What are the possible reasons?

 

Please help me.

 

Appreciate your help.

 

Thanks