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
subbaiah Godenasubbaiah Godena 

how to insert the data through visualforce page in custom settings

Hi
     how to insert the data through visualforce page in custom settings?
Martijn SchwarzerMartijn Schwarzer
Hi Subbaiah,

You can insert data into custom settings just like you would do with custom objects.

Example:

These are the details of my Custom Setting:

User-added image

At this time, I have no records yet for this custom setting:

User-added image

I created a very simple Visualforce page that lists the fields and a Save button:
 
<apex:page controller="EndpointInformationController">
    <apex:form>
    	<apex:pageBlock title="Endpoint Information">
            <apex:pageBlockButtons>
            	<apex:commandButton action="{!saveRecord}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="details">
                <apex:inputField value="{!endpoint.Name}"/>
                <apex:inputField value="{!endpoint.Endpoint__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

And the Controller which saves the record to the database:
 
public class EndpointInformationController {
    public Endpoint_Information__c endpoint{get; set;}
    
    /* Constructor */
    public EndpointInformationController(){
        //Initialize new custom setting record
        this.endpoint = new Endpoint_Information__c();
    }
    
    //Insert the new custom setting record in the database
    public PageReference saveRecord(){
        insert this.endpoint;
        
        //Redirect to new record detail page
        return new PageReference('/' + this.endpoint.Id);
    }
}

If you open the page, enter the fields and save the record, a new custom settings record will be inserted in the database:

User-added image

After saving, the detail page of the new record is shown:

User-added image

Clicking "Back to List" link will show you the list with the new record:

User-added image

Hope this helps!

Best regards,
Martijn Schwärzer
A NikhilA Nikhil

Hi Martijn Schwärzer,
This code is working fine for inserting the values into custom settings using VF page.I tried to write the code to update the same set of values biut I am not able to do so. Could you help us in writing apex code and VF apge for upadting the custom settings.
Thanks
Nikhil

Dennis H PalmerDennis H Palmer
For updating Org-wide record...

Visualforce Page
<apex:page controller="EndpointInformationController">
    <apex:form>
    	<apex:pageBlock title="Endpoint Information">
            <apex:pageBlockButtons>
            	<apex:commandButton action="{!saveRecord}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Details">
                <apex:inputField value="{!endpoint.Endpoint__c}"/>
                <apex:inputHidden value="{!endpoint.Name}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
APEX Controller
public class EndpointInformationController {
    public Endpoint_Information__c  endpoint {get; set;}
    
    /* Constructor */
    public EndpointInformationController() {
        //Initialize new custom setting record
        this.endpoint = Endpoint_Information__c.getOrgDefaults();
    }
    
    //Insert the new custom setting record in the database
    public PageReference saveRecord() {
        update this.endpoint;
        
        return null;
    }
}


 
sakshi gupta 67sakshi gupta 67
hii, 
how can we create record in custom setting through lightening web component ,as object api name is not supported for the custom setting?
please help.
thanks