Wednesday 7 May 2014

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





Hi guys,

In this post i am showing how can we use the power of javascript in VF page and inserting record in salesforce without any standard/custom controller or Apex.

By using AJAX Toolkit we can do this task easily.

AJAX Toolkit divides in two type synchronous and asynchronous call.

It works in three simple steps:
  1. Connecting to the AJAX Toolkit(By using login methods or getting Session_ID)
  2. Embedding the API methods in JavaScript.
  3. Processing the results.
in following example i am using synchronous call :-


Screen Shoots:-


 After inserting of record you are having ID of record :-


Happy Coding...:)

Thanks
Anurag Jain

2 comments:

  1. Anurag,

    Thanks for the post!

    This approach doesn't seem to comply with the MVC pattern. I'm curious to understand the pros/cons of using the AJAX toolkit for CRUD operations vs. the traditional controller-based approach. Would you mind touching on that a bit?

    Thanks,
    Martha

    ReplyDelete
    Replies
    1. Hi Martha,

      AJAX Toolkit is based on the partner WSDL and Using the AJAX Toolkit you can only calls the SOAP API, AJAX Toolkit can never make calls to the Controller methods.

      AJAX Toolkit is used AJAX works best with relatively small amounts of data (up to 200 records, approximately six fields with 50 characters of data each). The larger the data set returned, the more time it will take to construct and deconstruct a SOAP message.

      but using controller-based approach you can do any thing you want SOAP calls, REST calls,can play with large no of records etc.

      Thanks

      Delete