Insert Records in SF by using JavaScript without Apex classes or controller.

http://anuragsfdc.blogspot.in/2014/05/Insert-Records-SF-by-using-JavaScript.html

***************************************************

<apex:page id=”Page” sidebar=”false”>
<script src=”/soap/ajax/20.0/connection.js” type=”text/javascript”></script>
<script>
function insertAccount(){
// Getting Session ID.
sforce.connection.sessionId = “{!$Api.Session_ID}”;

//Creating New Account Record.
var account = new sforce.SObject(“Account”);
//Getting Account Name from inputText.
account.Name = document.getElementById(“Page:Form:PB:PBS:PBSI:Name”).value;

// This is the line where magic happens, calling Create() method.
var result = sforce.connection.create([account]);

if (result[0].getBoolean(“success”)) {
alert(“New Account is created with id ” + result[0].id);
} else {
alert(“failed to create new Account ” + result[0]);
}
}
</script>
<apex:form id=”Form”>
<apex:pageBlock title=”Insert Account” tabStyle=”Account” id=”PB”>
<apex:pageBlockSection title=”Account Name” columns=”1″ id=”PBS”>
<apex:pageBlockSectionItem id=”PBSI”>
<apex:outputLabel value=”Name” />
<apex:inputText title=”Name” id=”Name” />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons>
<apex:commandButton onclick=”return insertAccount();” value=”Save”/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

Print Friendly, PDF & Email
This entry was posted in Development. Bookmark the permalink.