You need to sign in to do that
Don't have an account?
Input Field on Wrapper Class Not Passing Inputs
I am having an issue passing an input field from a Visualforce page to new inserted records. The field I am trying to pass is 'Remarks_Special_Instructions__c' but when I put info in there it is not saving into the newly created records. I have tried a few different ways but no luck on any front. What are my issues? Thanks in advance!
Apex:
Visualforce:
Apex:
public with sharing class quoteAssociatedSiteExtension { //Our collection of the class/wrapper objects cContact public Quote theQuote {get; set;} public List<assLoc> assLocList {get; set;} public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { String quoteId = ApexPages.currentPage().getParameters().get('quoteId'); theQuote = [select Id, AccountId from Quote where Id =:quoteId limit 1]; } //This method uses a simple SOQL query to return a List of Contacts public List<assLoc> getAssLoc() { if(assLocList == null) { assLocList = new List<assLoc>(); for(Site__c s: [select Id, Name, Account__r.Id, City__c, Country__c,Order_Master_ID__c, Order_Master_Link__c, Site_ID__c, Site_Main_Phone__c, State__c, Street__c, Zip__c from Site__c where Account__r.Id=:theQuote.AccountId ]) { // As each contact is processed we create a new cContact object and add it to the contactList assLocList.add(new assLoc(s)); } } return assLocList; } public PageReference processSelected() { //We create a new list of Contacts that we be populated only with Contacts if they are selected List<Site__c> selectedAssociatedLocations = new List<Site__c>(); //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list for(assLoc aLoc: getAssLoc()) { if(aLoc.selected == true) { selectedAssociatedLocations.add(aLoc.st); } } // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc List<Associated_Location__c> nmal = new List<Associated_Location__c>(); for(Site__c al: selectedAssociatedLocations) { Associated_Location__c nal = new Associated_Location__c(); nal.Site__c = al.Id; nal.Quote__c = theQuote.Id; nmal.add(nal); } insert nmal; return new PageReference('/'+ApexPages.currentPage().getParameters().get('quoteId')); } // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value public class assLoc { public Associated_Location__c ac {get; set;} public Site__c st {get; set;} public Quote qt {get; set;} public Boolean selected {get; set;} //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false public assLoc(Associated_Location__c a) { ac = a; selected = false; } public assLoc(Site__c s) { st = s; selected = false; } public assLoc(Quote q) { qt = q; selected = false; } } }
Visualforce:
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension" > <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/> </apex:pageBlockButtons> <!-- In our table we are displaying the cContact records --> <apex:pageBlockTable value="{!AssLoc}" var="a" id="table"> <apex:column > <!-- This is our selected Boolean property in our wrapper class --> <apex:inputCheckbox value="{!a.selected}"/> </apex:column> <!-- This is how we access the contact values within our cContact container/wrapper --> <apex:column value="{!a.st.Street__c}" /> <apex:column value="{!a.st.City__c}" /> <apex:column value="{!a.st.State__c}" /> <apex:column value="{!a.st.Zip__c}" /> <apex:column headerValue="{!$ObjectType.Associated_Location__c.Fields.Remarks_Special_Instructions__c.Label}"> <apex:inputField value="{!a.ac.Remarks_Special_Instructions__c}" required="false"/> </apex:column> <apex:column value="{!a.st.Site_Main_Phone__c}" /> <apex:column value="{!a.st.Order_Master_Link__c}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Please check Field level security and object level security(Create,Edit..) for current user.
Try something like this:
That feels pretty close but it is still not taking the inputfield values. Do I need to set those somewhere? This is the first slightly large apex/visualforce code I have written and have no real developer experience so I honestly have no clue what I am doing. Thanks in advance!
So you're saying the Remarks_Special_Instructions__c data still ins't getting set?
Try doing some print statements to debug it.
Put System.debug statements into the processSelected method and print out a bunch of things to see what the values are. Let me know if you need help on how to do this.
In the wrapper class, the constructors don't initialize all of the variables. Specifically in the one that takes a site (the one you are using in this code) the associated_location__c variable "ac" would be left null since you didnt instantiate it. Try instantiating all of the variables in your constructors:
...
ac = new Associated_Location__c();
..
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm
See the section on null variables and initial values.