• Debra Shoup 4
  • NEWBIE
  • 10 Points
  • Member since 2018
  • Salesforce Administrator
  • PowerPlan, Inc.

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
I’m working on my first Visualforce page and controller. Thanks to others on the community, I’ve gotten everything to work and now I need to write the test class to move it to production. I’ve never done this before. I’ve completed the Apex Testing module in Trailhead, but I’m still lost on how to create the test for my project. This just is not clicking for me. Below is my code for the Visualforce page and for the controller. Help is greatly appreciated.

<apex:page StandardController="Contract" extensions="ContractProductsController">
  <apex:form >
        <apex:pageBlock >
                       <apex:pageBlockTable value="{!lineItems}" var="oli">
                 <apex:column >
                  <apex:facet name="header">Product Code</apex:facet>
                       {!oli.PricebookEntry.Product2.ProductCode}
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Product</apex:facet>
                       {!oli.PricebookEntry.Name}
                </apex:column>
              </apex:pageBlockTable>  
          
          </apex:pageBlock>
    </apex:form>
</apex:page>


Controller:

public class ContractProductsController {
 public List<OpportunityLineItem> lineItems { get; set; }
   
    Public ContractProductsController( ApexPages.StandardController std )
                {
                                if( std.getRecord().Id != null )
                                {
                                                Contract con = [ Select Id, Opportunity__c from Contract where Id =: std.getRecord().Id ];
                                               
                                                lineItems = [ Select Id, OpportunityID, PricebookEntry.Name, PricebookEntry.Product2.ProductCode,Product2ID,PricebookEntryID
            from OpportunityLineItem where OpportunityID =: con.Opportunity__c ];
                                }
                                else
                                {
                                                lineItems = new List<OpportunityLineItem>();
                                }
    }        
}
Hi,
I’m hoping someone can help me with a Visualforce page I’m trying to create. The requirement is to show the opportunity line items on the contract page. In our system, the opportunity is created, products are added and then a contract record is created from the opportunity.

The users don’t need to be able to edit the products, just view the product code and product name on the contract page. I’m new to developing and working my way through Visualforce and Apex on Trailhead, but I need to get this request complete pretty quickly.

Below is the code I have so far, which I've pieced together from various similar posts. However, it’s producing an error: List controllers are not supported for OpportunityLineItem. Any help would be greatly appreciated. Thank you so much!


My Visualforce Page
<apex:page >StandardController="Contract" extensions="ContractProducts">
  <apex:form >
        <apex:pageBlock title="Products">
            <apex:pageBlockTable value="{!lineItems}" var="oli">
                    <apex:column value="{!oli.ProductCode}"/>
                <apex:column value="{!oli.PricebookEntry.Name}"/>
             </apex:pageBlockTable>   
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Apex Class
public class ContractProductsController {
 public List<OpportunityLineItem> lineItems { get; set; }
   Public ContractProductsController( ApexPages.StandardController std )
                {
                     if( std.getRecord().Id != null )
                                {
            Contract con = [ Select Id, Opportunity__c from Contract where Id =: std.getRecord().Id ];
                                               
    lineItems = [ Select Id, Opportunityid, PricebookEntry.Name, ProductCode
            from OpportunityLineItem where Opportunityid =: con.Opportunity__c ];
                                }
                                else
                                {
              lineItems = new List<OpportunityLineItem>();
                                }
    }        
}
 
First, I’m not a developer and this is my first time attempting to create a Visualforce page and, I’m sure this is very basic to most on here, but I need some help. What I want to do: Override the “New” button on a custom child object to Contacts. The object is called Equipment Assignments and I want users to be able to request equipment from their Contact record in Salesforce. So I want to call the button “New Equipment Request.”  Basically, I want the user to create the record, the have it go through an approval process so the project manager can approve or disapprove the request.
 
I have created the VF page with the below code and when I preview it, everything looks right. I’ve created my custom button and placed it on the related list, shown in the image. However, when I click on the New Equipment Request button, I get the error “Id value 0033C000006pAjR is not valid for the Equipment_Assignments__c standard controller”. So, obviously I need to do more, but I don’t know what that is. I’ve read some posts about public class and wrapper class, but I’m not sure how to go about writing any of that or what exactly I would even need.

Also, I am using record types on the Equipment Assignments, so I need to incorporate that into the VF. I also want to pull in some custom information from the contact record, such as the Manager and Department. I’m not sure how to do that.
 
<apex:page standardController ="Equipment_Assignments__c">
<apex:form >
   
<apex:pageBlock title="Equipment Request">
   
  <apex:pageBlockSection title="Requestor Information">
    <apex:inputField value="{!Equipment_Assignments__c.name}"/>
  
    <apex:inputField value="{!Equipment_Assignments__c.Department__c}"/>
    <apex:inputField value="{!Equipment_Assignments__c.Assigned_To__c}"/>
    <apex:inputField value="{!Equipment_Assignments__c.Project__c}"/>
       
    </apex:pageBlockSection>  
  <apex:pageBlockSection title="Request Information">
    <apex:inputField value="{!Equipment_Assignments__c.Start_Date__c}"/>
    <apex:inputField value="{!Equipment_Assignments__c.End_Date__c}"/> 
 
      <apex:commandButton value="Submit Request" action="{!save}"/>
   </apex:pageBlockSection>
   
</apex:pageBlock>   
</apex:form>
</apex:page>
 
User-added image
I’m working on my first Visualforce page and controller. Thanks to others on the community, I’ve gotten everything to work and now I need to write the test class to move it to production. I’ve never done this before. I’ve completed the Apex Testing module in Trailhead, but I’m still lost on how to create the test for my project. This just is not clicking for me. Below is my code for the Visualforce page and for the controller. Help is greatly appreciated.

<apex:page StandardController="Contract" extensions="ContractProductsController">
  <apex:form >
        <apex:pageBlock >
                       <apex:pageBlockTable value="{!lineItems}" var="oli">
                 <apex:column >
                  <apex:facet name="header">Product Code</apex:facet>
                       {!oli.PricebookEntry.Product2.ProductCode}
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Product</apex:facet>
                       {!oli.PricebookEntry.Name}
                </apex:column>
              </apex:pageBlockTable>  
          
          </apex:pageBlock>
    </apex:form>
</apex:page>


Controller:

public class ContractProductsController {
 public List<OpportunityLineItem> lineItems { get; set; }
   
    Public ContractProductsController( ApexPages.StandardController std )
                {
                                if( std.getRecord().Id != null )
                                {
                                                Contract con = [ Select Id, Opportunity__c from Contract where Id =: std.getRecord().Id ];
                                               
                                                lineItems = [ Select Id, OpportunityID, PricebookEntry.Name, PricebookEntry.Product2.ProductCode,Product2ID,PricebookEntryID
            from OpportunityLineItem where OpportunityID =: con.Opportunity__c ];
                                }
                                else
                                {
                                                lineItems = new List<OpportunityLineItem>();
                                }
    }        
}
Hi,
I’m hoping someone can help me with a Visualforce page I’m trying to create. The requirement is to show the opportunity line items on the contract page. In our system, the opportunity is created, products are added and then a contract record is created from the opportunity.

The users don’t need to be able to edit the products, just view the product code and product name on the contract page. I’m new to developing and working my way through Visualforce and Apex on Trailhead, but I need to get this request complete pretty quickly.

Below is the code I have so far, which I've pieced together from various similar posts. However, it’s producing an error: List controllers are not supported for OpportunityLineItem. Any help would be greatly appreciated. Thank you so much!


My Visualforce Page
<apex:page >StandardController="Contract" extensions="ContractProducts">
  <apex:form >
        <apex:pageBlock title="Products">
            <apex:pageBlockTable value="{!lineItems}" var="oli">
                    <apex:column value="{!oli.ProductCode}"/>
                <apex:column value="{!oli.PricebookEntry.Name}"/>
             </apex:pageBlockTable>   
        </apex:pageBlock>
    </apex:form>
</apex:page>

My Apex Class
public class ContractProductsController {
 public List<OpportunityLineItem> lineItems { get; set; }
   Public ContractProductsController( ApexPages.StandardController std )
                {
                     if( std.getRecord().Id != null )
                                {
            Contract con = [ Select Id, Opportunity__c from Contract where Id =: std.getRecord().Id ];
                                               
    lineItems = [ Select Id, Opportunityid, PricebookEntry.Name, ProductCode
            from OpportunityLineItem where Opportunityid =: con.Opportunity__c ];
                                }
                                else
                                {
              lineItems = new List<OpportunityLineItem>();
                                }
    }        
}