+ Start a Discussion
Jack Thomas 3Jack Thomas 3 

Insert record to object

How i can insert record from vf page without using controller?
Best Answer chosen by Jack Thomas 3
Akshay_DhimanAkshay_Dhiman
Hi  Jack,
I hope this code will help you.
 
<apex:page standardController="Account">   //use standard controller for save data without controller
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlocksection columns="1">
                <apex:inputField value="{!Account.Name}"/>   //direct access Accounts’s Name,Phone,AccountNumber by the  Standard Controller
                <apex:inputField value="{!Account.Phone}"/>
                <apex:inputField value="{!Account.AccountNumber}"/>
            </apex:pageBlocksection>

            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}"  value="Create"/>   //Save action use for inserting and updating the records in standard controller
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>



In the above code using the  standardController instead of controller by which directly saves the data in any object which is custom or standard.Only take an action {!save} on any event.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Regards
Akshay

All Answers

Sumeet_ForceSumeet_Force
Use JS Remoting.
Srinivas AnnamSrinivas Annam

Please check with below link...

https://developer.salesforce.com/forums/?id=9060G000000UXjPQAW

Srinivas AnnamSrinivas Annam
Insert record from Vf Page Please refer the below link for reference.

https://apexcoder.com/2016/04/13/how-can-we-insert-update-and-delete-a-record-in-a-visualforce-page/

I hope it will be helpful to you.

Please mark it as best answer if the information is informative.

Best Regards,
Srinivas
Amit Chaudhary 8Amit Chaudhary 8
You Can do same with standardController method
<apex:page standardController="Account"> 
 <apex:form> 
 <apex:pageBlock> 
 <apex:pageBlocksection columns="1">
 <apex:inputField value="{!Account.Name}"/>
 <apex:inputField value="{!Account.BillingCity}"/>
 <apex:inputField value="{!Account.BillingState}"/>
 <apex:inputField value="{!Account.BillingCountry}"/>
 <apex:inputField value="{!Account.BillingPostalCode}"/>
 </apex:pageBlocksection>
 
 <apex:pageBlockButtons >
     <apex:commandButton action="{!save}" value="Save"/>
 </apex:pageBlockButtons> 
 </apex:pageBlock> 
 </apex:form>
</apex:page>

Let us know if this will help you
Akshay_DhimanAkshay_Dhiman
Hi  Jack,
I hope this code will help you.
 
<apex:page standardController="Account">   //use standard controller for save data without controller
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlocksection columns="1">
                <apex:inputField value="{!Account.Name}"/>   //direct access Accounts’s Name,Phone,AccountNumber by the  Standard Controller
                <apex:inputField value="{!Account.Phone}"/>
                <apex:inputField value="{!Account.AccountNumber}"/>
            </apex:pageBlocksection>

            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}"  value="Create"/>   //Save action use for inserting and updating the records in standard controller
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>



In the above code using the  standardController instead of controller by which directly saves the data in any object which is custom or standard.Only take an action {!save} on any event.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Regards
Akshay
This was selected as the best answer
Jack Thomas 3Jack Thomas 3
Hi Thanks to all for your response and @Akshay thanks for explaination.