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
taaataaa 

Save in Controller

Hi All,

 

Below pasted are my code for VF page, but it is not saved. What to do? Value mapped but when I am saving, it is refreshing the page,

 

VF page:

<apex:page standardController="Contact" extensions="ContactExtension" >

<apex:form >
<apex:outputPanel id="scriptRefresh">

<script type="text/javascript">

function readonly(input) {

if(input){

document.getElementById('{!$Component.pgBlock.chkboxRefresh.SiteAddRefresh}').style.visibility = 'visible';
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailst.txtMail_Str}').disabled = true;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailcity.txtMail_city}').disabled = true;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailState.txtMail_State}').disabled = true;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailPcode.txtMail_PCode}').disabled = true;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailcountry.txtMail_Country}').disabled = true;

}
else {
document.getElementById('{!$Component.pgBlock.chkboxRefresh.SiteAddRefresh}').style.visibility = 'hidden';
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailst.txtMail_Str}').disabled = false;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailcity.txtMail_city}').disabled = false;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailState.txtMail_State}').disabled = false;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailPcode.txtMail_PCode}').disabled = false;
document.getElementById('{!$Component.pgBlock.pbsRefresh.pbsiMailcountry.txtMail_Country}').disabled = false;

}

}

</script>

</apex:outputPanel>

<apex:pageBlock mode="edit" id="pgBlock">

<apex:actionFunction action="{!showAccount}" name="mydispayAccount" reRender="SiteAddRefresh,scriptRefresh" >
<apex:param name="accDisply" assignto="{!accDisply}" value="" />
</apex:actionFunction>

<apex:actionFunction action="{!UpdateContact}" name="myAction" reRender="pbsRefresh" oncomplete="readonly(true);">
<apex:param name="acc" assignto="{!acc}" value="" />
</apex:actionFunction>



<apex:pageBlockSection title="Address Information" id="chkboxRefresh" Columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Select address from existing address " />
<input id="checkbox" type="checkbox" onclick="readonly(this.checked);" />
</apex:pageBlockSectionItem>

<apex:outputPanel style="visibility:hidden" id="SiteAddRefresh">
<apex:outputLabel value="Site Address" style="font-weight:bold;padding-right:15px;font-size: 91%;color: #4A4A56;text-align: left;font-family: Arial,Helvetica,sans-serif;" />
<apex:inputField value="{!contList.Site_Address__c}" onchange="myAction(this.value);" /><br/>
</apex:outputPanel>

</apex:pageBlockSection>
<apex:pageBlockSection columns="2" id="pbsRefresh">


<apex:pageBlockSectionItem id="pbsiMailst">
<apex:outputLabel value="MailingStreet" />
<apex:inputField value="{!contList.MailingStreet}" id="txtMail_Str" />
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem id="pbsiMailcity" >
<apex:outputLabel value="MailingCity" for="txtMail_city"/>
<apex:inputField value="{!contList.MailingCity}" id="txtMail_city"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem id="pbsiMailState" >
<apex:outputLabel value="MailingState" for="txtMail_State"/>
<apex:inputfield value="{!contList.MailingState}" id="txtMail_State" />
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem id="pbsiMailPcode" >
<apex:outputLabel value="Mailing PostalCode" for="txtMail_PCode"/ >
<apex:inputfield value="{!contList.MailingPostalCode}" id="txtMail_PCode"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem id="pbsiMailcountry" >
<apex:outputLabel value="Mailing Country" for="txtMail_Country"/>
<apex:inputfield value="{!contList.MailingCountry}" id="txtMail_Country"/>

</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>


</apex:pageBlock>
</apex:form>
</apex:page>

 

 

<---------------->

Controller:

public with sharing class ContactExtension{
// public String phone{get;set;}
public string acc{get;set;}

public string accDisply{get;set;}
public Account accList{get;set;}

public boolean siteAdd{get;set;}
public string MailingPostalCode1{get;set;}
Public List<Site_Address__c> lstSiteAddress ;
public Contact contList{get;set;}

public ContactExtension(ApexPages.StandardController controller) {
//siteAdd=false;
}


public void UpdateContact(){

Try {
contList = new Contact();
lstSiteAddress = [Select Account__c, Shipping_street__c, Shipping_State_Province__c,Shipping_Country__c, Shipping_city__c, Shipping_Zip_Postal_Code__c, Site_Number__c from Site_Address__c where name =: acc];
system.debug('TEST@@@@@@@@@@@'+lstSiteAddress);

contList.MailingStreet = lstSiteAddress[0].Shipping_street__c;

contList.MailingCity = lstSiteAddress[0].Shipping_city__c;
contList.MailingState = lstSiteAddress[0].Shipping_State_Province__c;
contList.MailingPostalCode =lstSiteAddress[0].Shipping_Zip_Postal_Code__c;
contList.MailingCountry = lstSiteAddress[0].Shipping_Country__c;
system.debug('TEST@@@@@@@@@@@'+MailingPostalCode1+' --------------'+lstSiteAddress);
}
catch(exception ext) {

system.debug('Test'+ext);
}


}

public void showAccount() {
system.debug('accDisply&&&&&&&'+accDisply);
if(accDisply=='true') {
// siteAdd =true;

} else {
// siteAdd=false;
}
}
}

 

Thanks,

Ayesha!

colemabcolemab

Do you have any DML in your code to write the changes to the database?

 

For example:

 

Upsert contList;