You need to sign in to do that
Don't have an account?
rickyn
Setter Method not Working
Hi - I can't seem to figure out how to get my setter method to bind to my page. The none of my setter methods are being called.
public with sharing class ConRegWizController { Account account; Shadow_Account__c shadowacct; Contact primarycontact; User user = [SELECT id, AccountId, ContactID FROM User WHERE id = : UserInfo.getUserId()]; public ConRegWizController() { //Retrieve records for Portal Users if(user.AccountID != NULL ) { account = [SELECT id, Name FROM Account WHERE id = : user.AccountID]; shadowacct = [SELECT id, Name, Con_Annual_Revenue__c, Con_In_Business_Since__c, City__c, Country__c, Postal_Zip_Code__c, Province_State__c, Street__c, Con_Legal_Business_Name__c, Con_Number_of_Employees__c, Con_Type_of_Business__c, Website__c, Con_Work_Category__c FROM Shadow_Account__c WHERE Account__c = : user.AccountID]; primarycontact = [SELECT id, LastName, FirstName, Phone, MobilePhone, Email, Primary_Contact__c FROM Contact WHERE AccountID = :user.AccountID AND Primary_Contact__c = TRUE ]; } //Retrieve records for Standard Users else { account = [SELECT id, Name FROM Account WHERE id = :ApexPages.currentPage().getParameters().get('id')]; shadowacct = [SELECT id, Name, Con_Annual_Revenue__c, Con_In_Business_Since__c, City__c, Country__c, Postal_Zip_Code__c, Province_State__c, Street__c, Con_Legal_Business_Name__c, Con_Number_of_Employees__c, Con_Type_of_Business__c, Website__c, Con_Work_Category__c FROM Shadow_Account__c WHERE Account__c = :ApexPages.currentPage().getParameters().get('id')]; primarycontact = [SELECT id, LastName, FirstName, Phone, MobilePhone, Email, Primary_Contact__c FROM Contact WHERE AccountID = :ApexPages.currentPage().getParameters().get('id') AND Primary_Contact__c = TRUE ]; } } public Account getAccount() { if(account == null) account = new Account(); return account; } public void setAccount(Account ACCT) { Account = ACCT; } public Shadow_Account__c getShadowAcct() { system.debug('DEBUG: shadowacct =' + shadowacct); if(shadowacct == null) shadowacct = new Shadow_Account__c (); return shadowacct; } public void setShadowAcct(Shadow_Account__c SA) { system.debug('DEBUG: Entering Shadow Acct Setter method'); //Does not enter method ShadowAcct = SA; } public Contact getprimaryContact() { system.debug('DEBUG: primarycontact =' + primarycontact); if(primarycontact == null) primarycontact = new Contact(); return primarycontact; } public void setprimaryContact(Contact CONT) { system.debug('DEBUG: Entering Primary Contact Setter method'); //Does not enter method primaryContact = CONT; } public PageReference step1() { return Page.ContractorRegistrationStep1 ; } public PageReference step2() { return Page.ContractorRegistrationStep2; } public PageReference step3() { return Page.ContractorRegistrationStep3 ; } public PageReference step4() { return Page.ContractorRegistrationStep4 ; } public PageReference step5() { return Page.ContractorRegistrationStep5 ; } Public pageReference Save() { system.debug('DEBUG: shadowacct =' + shadowacct.Con_Legal_Business_Name__c); system.debug('DEBUG: primarycontact =' + primarycontact.LastName); update shadowacct; update primarycontact; /*PageReference ContractorDetails = Page.ContractorDetails; ContractorDetails.getParameters().put('ID',acct.ID); ContractorDetails.setRedirect(true); return ContractorDetails; */ return Page.ContractorRegistrationStep5; }
<apex:page sidebar="false" Controller="ConRegWizController"> <apex:sectionHeader title="Contractor Registration" subtitle="1 of 5 Company & Contact Information"/> <apex:form > <apex:pageBlock mode="Detail" > <apex:pageBlockButtons location="both"> <apex:commandButton action="{!Save}" value="Save & Exit" styleClass="btn" onclick="return confirmExit()" immediate="true"/> <apex:commandButton action="{!Cancel}" value="Cancel" styleClass="btn" onclick="return confirmCancel()" immediate="true"/> <apex:commandButton value="Next" action="{!Step2}" styleClass="btn" /> </apex:pageBlockButtons> <apex:pageBlockSection title="{!Account.Name} Information"> <apex:inputField value="{!ShadowAcct.Name}"/> <apex:inputField value="{!ShadowAcct.Con_Work_Category__c}"/> <apex:inputField value="{!ShadowAcct.Con_Legal_Business_Name__c}"/> <apex:inputField value="{!ShadowAcct.Con_Type_of_Business__c}"/> <apex:inputField value="{!ShadowAcct.Street__c}"/> <apex:inputField value="{!ShadowAcct.Con_Number_of_Employees__c}"/> <apex:inputField value="{!ShadowAcct.City__c}"/> <apex:inputField value="{!ShadowAcct.Con_Annual_Revenue__c}"/> <apex:inputField value="{!ShadowAcct.Province_State__c}"/> <apex:inputField value="{!ShadowAcct.Con_In_Business_Since__c}"/> <apex:inputField value="{!ShadowAcct.Postal_Zip_Code__c}"/> <apex:inputField value="{!ShadowAcct.Website__c}"/> <apex:inputField value="{!ShadowAcct.Country__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Primary Contact Information" rendered="{!PrimaryContact.Primary_Contact__c}"> <apex:inputField value="{!PrimaryContact.FirstName}"/> <apex:inputField value="{!PrimaryContact.Phone}"/> <apex:inputField value="{!PrimaryContact.LastName}"/> <apex:inputField value="{!PrimaryContact.MobilePhone}"/> <apex:inputField value="{!PrimaryContact.Email}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
You have the immediate attribute set to true on the save button - this will discard all user changes and thus your setters won't be called.
All Answers
Perhaps you have a validation that is failing in which caseinput values are not bound to controller data.
You should include an apex:messages in your page to make sure any error messages are displayed somewhere....
You have the immediate attribute set to true on the save button - this will discard all user changes and thus your setters won't be called.
I have a similar issue. Updates are not being updated from the visualforce page. Here is the Controller:
public with sharing class GordonTestController {
public String TestUpdate;
public QuoteLineItem QuoteLineItem01;
public GordonTestController() {
}
public void populate(){
QuoteLineItem Qli01r =
[SELECT ID,
PriceBookEntryID,
QuoteID,
Quantity,
Cost__c,
UnitPrice,
Description,
Product_Alias__c,
ListPrice,
Source__c,
Discount,
PricebookEntry.Product2.Name
FROM QuoteLineItem WHERE ID = '0QLP00000000fd2' FOR UPDATE][0];
QuoteLineItem01 = Qli01r;
}
public QuoteLineItem getQuoteLineItem01(){
if(QuoteLineItem01 == null){
}
return QuoteLineItem01;
}
private void setQuoteLineItem01(QuoteLineItem QuoteLineItem01){
this.QuoteLineItem01 = QuoteLineItem01;
}
Public Void Testupdate(){
setQuoteLineItem01(QuoteLineItem01);
}
Public Void TestAdd(){
QuoteLineItem01.Product_Alias__c ='TEST 123';
Update QuoteLineItem01;
}
}
AND THE MARKUP:
<apex:page Controller="GordonTestController" >
<apex:pageBlock >
<apex:pageblockbuttons location="top">
<apex:form >
<apex:commandButton Value="Add to Current Quote" Action="{!TestAdd}" />
<apex:commandButton Value="Populate" Action="{!Populate}" />
<!-- <apex:commandButton Value="Cancel" />
--> </apex:form>
</apex:pageblockButtons>
<br/>
<apex:form >
<table>
<tr>
<td>
<apex:outputtext Value="Product Name" /><br/>
<apex:OutputText Value="{!QuoteLineItem01.PricebookEntry.Product2.Name}"/>
</td>
<td>
<apex:outputtext Value="Product Alias" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.Product_Alias__c}" />
</td>
<td>
<apex:outputtext Value="Line Item Description" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.Description}"/>
</td>
<td>
<apex:outputtext Value="Source" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.Source__c}"/>
</td>
<td>
<apex:outputtext Value="Unit Cost" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.Cost__c}"/>
</td>
<td>
<apex:outputtext Value="List Price" /><br/>
<apex:outputtext Value="{!QuoteLineItem01.ListPrice}"/>
</td>
<td>
<apex:outputtext Value="Discount" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.Discount}"/>
</td>
<td>
<apex:outputtext Value="SalesPrice" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.UnitPrice}"/>
</td>
<td>
<apex:outputtext Value="Quantity" /><br/>
<apex:inputfield Value="{!QuoteLineItem01.Quantity}"/>
</td>
</tr>
</table>
<br/>
</apex:form>
</apex:Pageblock>
<br/>
<br/>
</apex:page>
Try adding <apex:pagemessage/> to your visualforce page to check if there are any errors