function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JamesCoopeViconJamesCoopeVicon 

Opportunity Line Item List

Below is a controller I have written to allow the update of OpportunityLineItem Quantity_Shipped__c with a VF page I have created. Please can someone help write a test for this.

 

 

public class OppLineListCon {

 

    public PageReference cancel() {

        Pagereference p = new Pagereference('/' + Apexpages.currentPage().getParameters().get('id'))  ; 

        p.setRedirect(true);    

        return p;

    }

 

    public List<OpportunityLineItem> LineItems {

        get {

            LineItems = [select 

                    TotalPrice, 

                    UnitPrice, 

                    Quantity, 

                    PricebookEntry.Product2.Name, 

                    PricebookEntry.Product2.Description,                    

                    Quantity_Shipped__c, 

                    Description  

                    from OpportunityLineItem 

                    where OpportunityId = :Apexpages.currentPage().getParameters().get('id')];

            return LineItems;

        }

        set;

    }

 

    public Pagereference save(){

        Pagereference p = new Pagereference('/' + Apexpages.currentPage().getParameters().get('id'))  ;  

 

        try {

            update LineItems; 

        }

        catch(System.DMLException e) {

           ApexPages.addMessages(e);

           system.debug(e);

           return null;

        } 

        p.setRedirect(true);    

        return p;

    }

}

 

 

here is the code for the page


<apex:page controller="OppLineListCon" tabStyle="Asset">
    <apex:form >
        <apex:pageBlock title="Edit Ship details" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons> 
            <apex:pageBlockTable value="{!LineItems}" var="i">
                <apex:column headerValue="Product">
                    <apex:OutputText value="{!i.PricebookEntry.Product2.Name}" style="font-size:13px"/>
                    <br></br>
                    <apex:OutputText value="{!i.PricebookEntry.Product2.Description}" style="font-size:11px"/>
                </apex:column>                
                <apex:column headerValue="Ship Qty">
                    <apex:inputField value="{!i.Quantity_Shipped__c}" />
                </apex:column>                
            </apex:pageBlockTable>      
         </apex:pageBlock>
        
    </apex:form>
    </apex:page>
<apex:page controller="OppLineListCon" tabStyle="Asset">    <apex:form >        <apex:pageBlock title="Edit Ship details" mode="edit">            <apex:pageMessages />            <apex:pageBlockButtons location="top">                <apex:commandButton value="Save" action="{!save}"/>                <apex:commandButton value="Cancel" action="{!cancel}"/>            </apex:pageBlockButtons>             <apex:pageBlockTable value="{!LineItems}" var="i">                <apex:column headerValue="Product">                    <apex:OutputText value="{!i.PricebookEntry.Product2.Name}" style="font-size:13px"/>                    <br></br>                    <apex:OutputText value="{!i.PricebookEntry.Product2.Description}" style="font-size:11px"/>                </apex:column>                                <apex:column headerValue="Ship Qty">                    <apex:inputField value="{!i.Quantity_Shipped__c}" />                </apex:column>                            </apex:pageBlockTable>               </apex:pageBlock>            </apex:form>    </apex:page>