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
Anu-cnpAnu-cnp 

One Record Restriction

Hi

 

I have a problem with page refreshing. I  want a configuration setting for the objects to update. I have created an object to maintain the record. I need only one record per user in that object.

 

For that I have written code in constructor so that each time a page is refreshing another record gets created.

 

Can any one of you modify my code and send back to me. I have to update only one record. No need of creating another record.

 

Page:

 

 


 

<apex:page controller="SettingsController">

 

 <apex:form id="form">  

 

        <apex:sectionHeader title="Object Settings" subtitle="Configure Settings">

 

            <description>

 

                Settings that control the behavior of the Donor Management package. Changing these will change how your Package behaves.
            </description>  
        </apex:sectionHeader>
        <apex:pageMessages id="pageMessages"/>
         <apex:pageBlock id="xmlsettings" title="XML Settings">
        <apex:pageBlockButtons >
             <apex:commandButton action="{!save}" Value="Update Settings"/>
         </apex:pageBlockButtons>
          <apex:pageBlockSection title="Contacts" >
                  <apex:inputField value="{!newSetting.Contacts__c}"  onClick="hideAccount(this)" />
             </apex:pageBlockSection>
  
             <apex:pageBlockSection title="Accounts">
                 <apex:inputField value="{!newSetting.Accounts__c}" />
             </apex:pageBlockSection>
     
            
             <apex:pageBlockSection title="Opportunities">
                 <apex:inputField value="{!newSetting.Opportunities__c}"/>
             </apex:pageBlockSection>
             <apex:pageBlockSection title="Households">
                  <apex:inputField value="{!newSetting.Households__c}"/>
             </apex:pageBlockSection>
        </apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

 

 

 

 

Controller:

 

 

 

 

 

 

 

public with sharing class SettingsController {


XML_Setting__c newSetting;

    

    public XML_Setting__c getnewSetting() {return newSetting;}

    public void setnewSetting(XML_Setting__c newSetting) {this.newSetting= newSetting; }



    public SettingsController() {

    Id id = ApexPages.currentPage().getParameters().get('id');

   newSetting = (id == null) ? new XML_Setting__c() : [Select Name,Contacts__c,Accounts__c,Opportunities__c,Households__c from XML_Setting__c where Id=:id ];


    }

     

    

    public PageReference Save()

    {

  

          

             

        

     

       upsert newSetting;


        return null;

    

    }


}

 

Damien_Damien_

I'm not sure I completely understand what you want.... but

 

public PageReference Save()

{

     upsert newSetting;

       

     return new PageReference('/apex/SettingsPage?id=' + newSetting.id);

}

 

--------------------------------------------------------------------------------------------------------

I don't see why you aren't doing

<apex:page standardController="XML_Setting__c"  extensions="SettingsController">