Showing posts with label Javascript remoting. Show all posts
Showing posts with label Javascript remoting. Show all posts

Thursday, 4 January 2018

JavaScript Remoting

What is Javascript Remoting ?

This is a tool that developers can use to make an AJAX request from Visualforce page directly to an Apex Controller.

Key Features of Javascript Remoting?

Asynchronous 
Load only the initial page & Lazily load additional data.
Speed 
This is the fastest way of calling controller code.
No Forms
It will not post the form, So not keeping view state which improves the performance, On button click it will not load the whole page / no partial rendering. Only perform the action.
No SOQL Governor Limit
Javascript remoting calls don't count against SOQL Governor limit.
Responsive
It provides more responsive experience in both Mobile pages and web pages. 


Note : Salesforce has confirmed that the calls of the Remoting JavaScript methods do not count towards the limit of API calls


When to use Javascript Remoting?

Javascript Remoting can provide an efficient,responsive,and optimized user experience.

This is useful more in Mobile Web Development.


Limitations of Javascript Remoting ?

1. Since there is no forms and no view state maintained need to manage the state of page by self on the client side. Which may takes more development efforts.
2. Parameters need's to pass to the controller, It will take more maintenance in case of additional fields to the form.
3. All the validations need to be written.
4. Error handling must be incorporated into both page and the controller.
5. The response of the server is limited to a maximum of 15 Mb.
6. The response of the remote call must return maximum in 120 seconds.
7. As the response of the asynchronous server, conflicts or unexpected behaviors can occur, although very rarely.

Javascript Remoting VS ActionFunction ?


These are the 2 options to call the Apex from Javascript inside a Visualforce page.
Both will be used in different scenario's.

Javascript Remoting
Action Function
Performance much faster. No posting forms on request hence no view state.
Form will be post data on every request and View state will be transferred to the server.
There is no whole page/partial section re-rendering.
This can re-render the page or a specific section of the page to update it with new values from the controller instance.
Call back is available
No call back
Implementation is trickier.
Implementation is straight forward.

Note :
Any scenario where you don’t want to refresh the page/no partial page rendering and just want to perform an action.Then go for Javascript Remoting else Action Function can be used.


Visualforce Remote Objects VS  Javascript Remoting ?


Visualforce Remote Object
Javascript Remoting
The benefit of Remote Objects is that you can access server data without using API calls or writing Apex Code.
JavaScript Remoting needs Apex Code with the method @RemoteAction annotation
It's slower than the AJAX toolkit and the RemoteAction annotation.
This is the fastest way of calling controller code.
Currently creation of multiple records is not possible.
Creation of multiple records is possible.
The CRUD/FLS is automatically taken care in case of Remote Objects.
In apex you will need to write extra code to respect CRUD/FLS
Makes basic “CRUD” object access easy
It requires Javascript and Apex code
Supports minimal server-side application logic

Supports complex server-side application logic
Doesn’t provide automatic relationship traversals; you must look up related objects yourself

Handles complex object relationships better

  Test Class is not required, as no Controller is involved.

       Test Class is required, as Controller is involved.



Drawback of Visualforce Remote Object ?

The name space is hard coded in the mark-up. 


Javascript Remoting VS Lightning Component Framework?

Javascript Remoting Implementation ?

Action Function Implementation ?

Visualforce Remote Object Implementation ?

Thursday, 21 December 2017

Salesforce FAQ's

1. What is the return type of SOSL queries ?

List<List<SObject>>,Because it will give result from multiple objects

2. How can we schedule apex program ?

Implement a class with 'Schedulable' interface.
Then using 2 options able to schedule.
1.Apex class --> Schedule Apex 
2. Using System.schedule - Cron expression


3. What is the use of Database class in Apex?

Apex offers two ways to perform DML operations: using DML statements or Database class methods.
 Use Database class methods if you want to allow partial success of a bulk DML operation
—if a record fails, the remainder of the DML operation can still succeed.

4. What is analytical snapshot?

Analytical snapshot is also called as "Reporting Snapshot".

Its available on Tabular & Summary reports.

Reporting snapshots allow users to run reports and save the report results as records on custom objects. Unlike reports, users can schedule reporting snapshots to summarize data at specific times, and work with the summarized data similarly to how they work with other records in Salesforce.

Implementation:
Create a Tabular/Summary Report. 
Create a custom object to with the fields of above report & Map those to get the result of report into custom object.
This can be scheduled.



5. How can you setup governor limit email warnings in apex ?

  • APEX warning mails, which are sent when a class or trigger exceeds 50% of an APEX governor limit

Set up Apex exception email notifications


6.When do we need to use Javascript remoting and how is it implemented?

Jacascript Remoting :
JavaScript remoting is a tool that front-end developers can use to make an AJAX request from a Visualforce page directly to an Apex controller. JavaScript remoting allows you to run asynchronous actions by decoupling the page from the controller and to perform tasks on the page without having to reload the entire page.

Annotation :
@RemoteAction - 

When to Use ?
JavaScript remoting is optimized for use on mobile pages and on pages that use third-party JavaScript libraries. It enables dynamic, interactive pages that feel more responsive than traditional Visualforce pages.

You can load only the initial page and the data that you need to display the page, and then lazily load additional data that might not be used on the page immediately. 


7.There is a master-detail relationship between two objects and I want to ensure that the master object should not have more than 10 child records. How can we achieve this without using a trigger ?


Roll-Up Summary - Refer



8. What should be done to override the governor limit that restricts you from fetching more than 50,000 records in a SOQL query ?

Batch Apex can be used ,That process 50 million records

9.Suppose there are 2 Account records with 3 contacts associated against each Account record. What would be the end result, if I merge these two Account records ?

The final Account will have 6 contacts [3+3]




10. A custom field is made Read only from the Field level security and Required from Page layout. The Field will be ?Read Only for the User  (or) Required for the User  ?

Read Only for the User

Note: Field level security overrides the page layout settings

11.What are the different types of attributes that can be added to a lightning component?

12.What is the difference between application level events and component level events in lightning ?

13.What is the use of the tag in Lightning ?

14.How can two components who are not related to each other, interact with each other in lightning ?

Using Application Events.

15.What is the difference between pageblocktable and datatable in VF pages ?

16.What is the use of the ‘transient’ keyword ?
Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page.
17.What is the use of communities in Salesforce ?

18.Skinny Tables in salesforce ?

19.What are dynamic SOQL queries and how do you prevent SOQL injection in dynamic SOQL queries ?

20.What is apex managed sharing ?

21.What is the difference between approval process and workflow rules ?

22.What is the use of apex email services ?

23.Best way to page design for more number of fields(500) in salesforce ?

24.What is the difference between REST & SOAP ?

25. How to take design decision if service is exposed to both REST & SOAP ?

26.Explain end to end connecting for Inbound & Outbound ?

27.How to restrict the action of external request ?

28.What is connected App?

29. How to get the data captured in excel from different vendors to Salesforce ?