You need to sign in to do that
Don't have an account?

Controller
Hi
<apex:page standardStylesheets="false" expires="1" cache="false" showHeader="false" sidebar="false" id="page" controller="contacts">
<style type="text/css">
body {
font-size: 62.5%;
}
label {
display: inline-block;
width: 100px;
}
legend {
padding: 0.5em;
margin-left:auto;
margin-right:auto;
}
fieldset fieldset label {
display: block;
}
#signUpForm {
width: 500px;
margin-left:auto;
margin-right:auto;
margin-top:25px;
}
#signUpForm label {
width: 250px;
}
#signUpForm label.error, #commentForm button.submit {
margin-left: 253px;
}
#signUpForm {
width: 670px;
}
#signUpForm label.error {
margin-left: 250px;
width: auto;
display: block;
}
</style>
<form class="cmxform" id="signUpForm" >
<fieldset class="ui-widget ui-widget-content ui-corner-all">
<p>
<label>Firstname</label>
<input name="Firstname" id="Firstname" type="text" maxlegth="15" size="60" class="required" />
</p>
<p>
<label>Last Name</label>
<input name="Lastname" id="Lastname" type="text" size="60" class="required" />
</p>
<p>
<input type="button" onClick="signUp();" value="Create Account" class="button" />
</p>
</fieldset>
</form>
</apex:page>
I want to Add record in Account . Pls help me how to write Controller for this . Seconly is this can be done through Java Remoting if yes then how .
Thanks
Are you looking to create a new account or contact? The fields look contact-specific to me.
You should be able to do this using a standard controller rather than a custom controller. Have you excluded standard controllers for any reason?
try this Account Creation in Java Script Remoting
Controller Class
VFP
I hope it will help you
hi
do i need to enable any setting , Actually i tried to execute same code in my org. but its doesn't create Account. please help me regards in this issue
Thanks
Did you copy paste the code, it was working example. Did you get any compiler error. If not what happened when you click on button.Did you see any javascript error. Share you code that you used. One more thing that you are using Class and VFP of Salesforce API version 22.0 ?
my org version is 22.0 and please find class and vf page , and when i paste the Code into my org , i didnt get any compile errors . actually some times
my controller succesfully called and its doesnt inert the record .
Thanks
its working fine
Thanks
Hi jagjitsingh,
Did it worked for you as well , If yes please mark it as solution so that other's can also get benifit from it.
Hi Shashi
It is not inserting record.
Thanks
Could you show your code , because it is working at my org and Raj also confirm that it's working. So it might be possible that something is missing in your code.
Hi Shashi
Pls find attached the Apex Class
global with sharing class MyJSController1
{
public String accountName { get; set; }
public static Account account { get; set; }
public MyJSController1() { }
@RemoteAction
global static Account createAccount(String accountName) {
account = new account(Name = accountName);
insert account;
system.debug('account**'+account);
return account;
}
}
VFPage
<apex:page standardStylesheets="false" expires="1" cache="false" showHeader="false" sidebar="false" id="page" controller="MyJSController1">
<script>
function createAccountJSRemoting() {
/* alert('test');
var accountNameJS = document.getElementById('Firstname').value + document.getElementById('Lastname').value;
/*alert(accountNameJS);
MyJSController.createAccount( accountNameJS, function(result, event){
if (event.status)
{
alert('Account Created with ID : '+ result.Id);
}
else if (event.type === 'exception')
{
alert('Account Creation Failed');
}
else
{
alert('Event Message : '+ event.message);
}
}, {escape:true});
return false;
}
</script>
<style type="text/css">
body {
font-size: 62.5%;
}
label {
display: inline-block;
width: 100px;
}
legend {
padding: 0.5em;
margin-left:auto;
margin-right:auto;
}
fieldset fieldset label {
display: block;
}
#signUpForm {
width: 500px;
margin-left:auto;
margin-right:auto;
margin-top:25px;
}
#signUpForm label {
width: 250px;
}
#signUpForm label.error, #commentForm button.submit {
margin-left: 253px;
}
#signUpForm {
width: 670px;
}
#signUpForm label.error {
margin-left: 250px;
width: auto;
display: block;
}
</style>
<form class="cmxform" id="signUpForm" >
<fieldset class="ui-widget ui-widget-content ui-corner-all">
<p>
<label>Firstname</label>
<input name="Firstname" id="Firstname" type="text" maxlegth="15" size="60" class="required" />
</p>
<p>
<label>Last Name</label>
<input name="Lastname" id="Lastname" type="text" size="60" class="required" />
</p>
<p>
<input type="button" onClick="return createAccountJSRemoting();" value="Create Account" class="button" />
</p>
</fieldset>
</form>
</apex:page>
Please change Controller name in your VF page. that is MyJSController1 not MyJSController
Regards,
Here is your problem
In your Code you have made the class Name as MyJSController1
and in VFP where you are calling Remote JavaScript function
You are using MyJSController, so it will not work so either you need to change controller Name to MyJSController
or just change
to
Actual Class name and the Class Name while you call java script remote function has to be same