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
jagjitsingh@indivar.comjagjitsingh@indivar.com 

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

bob_buzzardbob_buzzard

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?

Shashikant SharmaShashikant Sharma

try this Account Creation in Java Script Remoting

Controller Class

global with sharing class MyJSController 
{
    public String accountName { get; set; }
    
    public static Account account { get; set; }
    
    
    public MyJSController() { }
     
    @RemoteAction
    global static Account createAccount(String accountName) {
        account = new account(Name = accountName);
        insert account;
        return account;
    } 
     
    
}

 

 VFP


<apex:page standardStylesheets="false" expires="1" cache="false" showHeader="false" sidebar="false" id="page" controller="MyJSController">
<script>
function createAccountJSRemoting() {

    var accountNameJS = document.getElementById('Firstname').value + document.getElementById('Lastname').value;;

    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>

 I hope it will help you

jagjitsingh@indivar.comjagjitsingh@indivar.com
Hi Bob
RajiRaji

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

 

 

 

Shashikant SharmaShashikant Sharma

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  ?

RajiRaji

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

controller
________________
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;
    } 
     
    
}
VF Page
__________
<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>

 

 

my controller succesfully called and its doesnt inert the record .

 

Thanks

 

RajiRaji

its working fine

 

 

Thanks

 

Shashikant SharmaShashikant Sharma

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.

jagjitsingh@indivar.comjagjitsingh@indivar.com

Hi Shashi

 

   It is not inserting record.

 

Thanks

Shashikant SharmaShashikant Sharma

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.

jagjitsingh@indivar.comjagjitsingh@indivar.com

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>

RajiRaji

Please change Controller name in your  VF page. that is MyJSController1 not MyJSController

 

 

Regards,

 

Shashikant SharmaShashikant Sharma

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

MyJSController.createAccount( accountNameJS, function(result, event)

 to

MyJSController1.createAccount( accountNameJS, function(result, event)

Actual  Class name and the Class Name while you call java script remote function has to be same