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
swathiswathi 

Insert Records without using save button

Hi All,

 

I want to insert the record automatically as soon as the page is loaded with on inputfield or inputtext without using save button.

 

Help me please.

 

Thanks in advance.

sfdcfoxsfdcfox

You can use an actionSupport tag that calls a function that calls a function to save the value.

 

For example:

 

<!-- page -->
<apex:inputField value="{!Record.CustomField__c}">
  <apex:actionSupport event="onchange" action+"{!saveFunction}" />
</apex:inputField>
public void saveFunction() {
  // do something that saves the record.
}

Take a look at the documentation for more details.

swathiswathi

Hi,

 

Thanks for your reply. But the action support is not working for my program.

 

<apex:page showHeader="false" sidebar="false" standardController="Account"  extensions="accountlongitude" ><apex:form >
<apex:inputfield id="theField"  value="{!Account.test__c}"><script> var theField = document.getElementById('{!$Component.theField}'); </script>  <apex:actionSupport event="onchange" action="{!save1}" /></apex:inputfield></apex:form>    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAeHfyTRY-0Gw97WpPMA_IDRRmUosZf0-11aAoS2Hz4zq1WSogUxQPmfTpYyhU_4lEIkJEo_1wIUOZFg"></script>    <script type="text/javascript">        google.load("maps", "2.x");       var s;       var addressPoint;             // Call this function when the page has been loaded        function initialize() {            if (GBrowserIsCompatible()) {                var map = new google.maps.Map2(document.getElementById("map"));                map.addControl(new GSmallMapControl());                                 var address = "{!Account.BillingStreet}" + ", " + "{!Account.BillingCity}" + ", " + "{!Account.BillingState}"+"{!Account.BillingPostalCode}" + "," + "{!Account.BillingCountry}";

                var geocoder = new GClientGeocoder();                geocoder.getLatLng(address, function(newPoint) {                    if (!newPoint) {                                            $('#textAddress').html('Bummer! We couldn\'t find the location you have in the Billing Address field. Try entering a new address and reloading the page...');                    } else {                                                             map.setCenter(newPoint, 14);                                              map.addOverlay(new GMarker(newPoint));                        var marker = new GMarker(newPoint);                        map.addOverlay(marker);                        marker.openInfoWindowHtml("<div style=\"float:left;\"><div style=\"font-family: arial, san-serif; padding-left:30px;\"><span style=\"font-weight:bold;\">{!Account.Name}</span><br/>{!Account.BillingStreet}<br/>{!Account.BillingCity}, {!Account.BillingState} {!Account.BillingPostalCode}<br/><br/></div></div>");                 s=newPoint;                               theField.value = s;                                                 }                });                           }        }             google.setOnLoadCallback(initialize);       </script>         <style>        .locationGoogleMap {            color:#4A4A56;            font-family:arial,helvetica,sans-serif;            font-size:12px;            font-weight:bold;            left:24.3%;            position:relative;        }                 #textAddress {            color:#000000;            font-family:arial,helvetica,sans-serif;            font-size:18px;            height:20px;            left:40%;            position:relative;        }          </style>        <apex:outputpanel id="googleMap" layout="none"  >        <span id="textAddress"></span>            <div id="contentMap" style="width: 100%; position:relative; margin-top:10px;">                <div id="map" style="height: 300px;"></div>            </div>            <span style="cursor: pointer;"             onclick="theField.value=s;">Hit Me</span>    </apex:outputpanel>   <apex:form ></apex:form></apex:page>?

 

This is my program I want to insert the javascript value ie., longitude and latitude value into a field  automatically when page is loaded without using the save button.