You need to sign in to do that
Don't have an account?
BillPowell__c
Custom Controller
Test Class (not working, can't figure out what to add/remove/edit)
VF Custom Cont. Test Class for Custom Object Help
I can't write code for the life of me but can usually plug in values and follow a pattern to have it do what I need it to. Had some help with a VF page, controller, and test class, but cant seem to get the test class to save. Can someone take a look at let me know what to change to make it pass? Thanks
VF Page
<apex:page controller="SampleController"> <apex:form > <apex:sectionHeader title="Mass Create Sample Order Line Items"></apex:sectionHeader> <apex:pageBlock title="Sample Order Edit" mode="edit"> <!--SAMPLE ORDER RECORD SECTION & FIELDS--> <apex:pageBlockSection title="Sample Order Information" collapsible="false" columns="2"> <apex:inputField label="Project Name" value="{!sampleOrder.Project_Name__c}" required="true"/> <apex:inputfield label="Order Status" value="{!sampleOrder.Status__c}" required="false"/> <apex:inputField label="Sales Rep" value="{!sampleOrder.McGrory_Sales_Rep__c}" required="true" /> <apex:outputfield label="Order Date" value="{!sampleOrder.Request_Date__c}"/> <apex:inputField label="Ship To" value="{!sampleOrder.Ship_To__c}" required="true"/> <apex:inputfield label="Ship Date" value="{!sampleOrder.Ship_Date__c}" required="false"/> <apex:inputField label="Notes" value="{!sampleOrder.Notes__c}" required="false"/> </apex:pageBlockSection> <apex:pageBlockSection title="Customer Information" collapsible="false" columns="2"> <apex:inputfield label="Company" value="{!sampleOrder.Company__c}" required="True"/> <apex:outputfield label="Address" value="{!sampleOrder.Address__c}"/> <apex:inputfield label="Contact" value="{!sampleOrder.Contact__c}" required="True"/> <apex:inputfield label="Contact Phone" value="{!sampleOrder.Contact_Phone__c}"/> <apex:inputField label="Contact Email" value="{!sampleOrder.Contact_Email__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Alternate Contact Information - If Not Shipping To Sales Rep Or Customer" collapsible="false" columns="2"> <apex:inputfield label="Alternate Company" value="{!sampleOrder.Alternate_Company__c}" required="False"/> <apex:inputfield label="Street Address" value="{!sampleOrder.Street_address__c}" required="False"/> <apex:inputfield label="Alternate Contact" value="{!sampleOrder.Alternate_Contact__c}" required="False"/> <apex:inputfield label="City" value="{!sampleOrder.City__c}" required="False"/> <apex:inputfield label="Alternate Phone" value="{!sampleOrder.Alternate_Phone__c}" required="False"/> <apex:inputfield label="State" value="{!sampleOrder.State__c}" required="False"/> <apex:inputfield label="Alternate Email" value="{!sampleOrder.Alternate_Email__c}" required="False"/> <apex:inputfield label="Zip/Postal Code" value="{!sampleOrder.Zip_Postal_Code__c}" required="False"/> </apex:pageBlockSection> <!--SAMPLE ORDER LINE ITEMS TABLE--> <apex:pageBlockSection title="Sample Order Line Items"> <apex:pageBlockTable id="tblLineItems" value="{!sampleOrderLineItems}" var="soli"> <apex:column > <apex:inputField value="{!soli.Quantity__c}"></apex:inputField> <apex:facet name="header"> Quantity </apex:facet> </apex:column> <apex:column > <apex:inputField value="{!soli.Description__c}"></apex:inputField> <apex:facet name="header"> Description </apex:facet> </apex:column> <apex:column > <apex:inputField value="{!soli.Width__c}"></apex:inputField> <apex:facet name="header"> Width </apex:facet> </apex:column> <apex:column > <apex:inputField value="{!soli.Height__c}"></apex:inputField> <apex:facet name="header"> Height </apex:facet> </apex:column> <apex:column > <apex:inputField value="{!soli.Product_Code__c}"></apex:inputField> <apex:facet name="header"> Product Code </apex:facet> </apex:column> <apex:facet name="footer"> <apex:commandButton value="Add Line" immediate="true" action="{!addLineItem}" rerender="tblLineItems"></apex:commandButton> </apex:facet> </apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"></apex:commandButton> <apex:commandButton value="Cancel" action="{!cancel}"></apex:commandButton> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Custom Controller
public class SampleController { public Sample_Order__c sampleOrder { get; set; } public List<Sample_Order_Line_Items__c> sampleOrderLineItems { get; set; } public SampleController() { sampleOrder = new Sample_Order__c(); sampleOrderLineItems = new List<Sample_Order_Line_Items__c>{ new Sample_Order_Line_Items__c() }; } public void addLineItem() { sampleOrderLineItems.add( new Sample_Order_Line_Items__c() ); } public PageReference save() { INSERT sampleOrder; for( Sample_Order_Line_Items__c soli : sampleOrderLineItems ) { soli.Sample_Order__c = sampleOrder.Id; } INSERT sampleOrderLineItems; return new PageReference( '/' + sampleOrder.Id ); } public PageReference cancel() { return new PageReference( '/home/home.jsp' ); } }
Test Class (not working, can't figure out what to add/remove/edit)
@isTest private class SampleController_UT { private static testmethod void testMethod1() { SampleController soObj = new SampleController(); soObj.addLineItem(); soObj.cancel(); soObj.Sample_Order__c = 'Test'; soObj.Quantity__c = 1; soObj.Project_name__c = 'Quote Testing Project'; soObj.McGrory_Sales_Rep__c = 'Bill Powell'; soObj.Ship_To__c = 'Customer'; try { soObj.save(); } catch(Exception ee) {} } }
I think this may help you. Thanks
Hemant