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 ?

 



Change Set to Package XML & Code Back Up

There is a simple way to get the Package.xml & Code Files from Change Set Using Workbench tool.



Wednesday 20 December 2017

REST API Security


What are the widely used authentication mechanism ?


  1. API key
  2. OAuth Access Tokens
  3. JSON Web Tokens (JWT)

API Key VS OAuth ?


APIK Keys : Mostly used for publicly exposed  web services.
Ex: Google APIs
OAuth : Authentication + Authorization

Ex: Google Map can be authenticated with 'API Key',
Facebook should use OAuth,Because each member data is confidential and if we give Facebook access via API key they should be able to perform any operation on any user data. 

Real Time Exp :

Outbound Integration :

In one scenario client shared the API key and directly used that while interacting with their REST Web service from salesforce.

--> In Salesforce Remote site settings configure the API details
--> Latest ,By using Named Credentials can configure API & Credential details

Inbound Integration :

In one scenario created a REST web service in the salesforce and exposed to other clients.
--> Created a API user and shared User name ,Password with client
--> Created a Connected App and generated Client ID (Consumer Key )& Client Secret (Consumer Secret) ,Share these details with client
-->By passing all these values with grant type password receives the Access Token
-->Then passing the access token can perform CRUD operations on REST web service

REST Integration

REST : Representational State Transfer

REST is a simple way of sending and receiving data between client and server.
It supports transfer of data by JSON/XML/Plain text

Idempotent :

If you send retry a request multiple times, that should be equivalent to single request modification.
Ex: Whenever you are trying to POST a comment in site,By mistake double clicked the submit it creates two comments in the server.Since POST is not Idempotent it behaves that way.

Safe Methods : 

Do not modify the resource in the server.

Ex: GET

What are the HTTP Methods for RESTful Services ?


HTTP Method
Details
Idempotent
Safe Method
GET
GET request should be used only to fetch some information from the server.
Yes
Yes
POST
POST request can be used to create a new resource or to update an existing resource in the server.
No
No
PUT
PUT If the Request-URI refers to an already existing resource – an update operation will happen, otherwise create operation should happen.

Note: If and only if updating the full content of the specified resource. PUT should be used.

Yes
No
PATCH
PATCH for Partial Update of content
No
No
DELETE
DELETE method should be used to remove or delete something from the server
Yes
No


POST VS PUT

Ideally POST should use for creation of new resource & PUT for updating the existing resource.

Again it's design decision :
1.The end point must be idempotent
2. If request URI contains the existing resource update operation if not create the mentioned resource

If any one is not needed use POST else use PUT

REST Integration Requirement / Salesforce Coding Test Scenario :

Get the GeoCode [Lattitue,Longitude] & formatted_address from GoogleMap API

Implementation :

Apex Class
Description
BLG_RESTAPICall_Ex
GoogleMapAPI call & Parsing the response JSON
BLG_GoogleMapAPIResponse
GoogleMapAPI JSON Response class



Is there any limit on REST request payload ?

HttpPost doesn't have size limit, but usually limited by the server to request is sent to.






Tuesday 19 December 2017

Bucket Fields

What is Bucket Field?

Bucket field is part of Saleforce Reporting.
It used to categorize data quickly without creating a formula or a custom field.

Can we use same Bucket Field on multiple reports?

No,
Below are the options :
1.Create a formula field on the object and use in multiple reports.
2.Create a report with bucket fields and save that template and build new reports from there.

Bucket fields can be used in charts ?

Yes

What are the types of Bucket Fields ?

There are 3 types 
  1. Numeric
  2. PickList
  3. Text
Example for Numeric Bucket Field :


Example for Picklist Bucket Field :



Example for Text Bucket Field :



Trigger.new Vs Trigger.newMap

What is the difference between Trigger.new & Trigger.newMap ?

Trigger.new : Returns list of the new versions of the sObject records

Trigger.newMap : A map of ID's to the new version of the sObject records.
Note : "Trigger.newMap" is available only in After Insert,Before Update,After Update.

Any workaround to use Trigger.newMap in Before Insert ?

Use below code to form the Map and use that in other places of logic.


Queueable Apex

What is Queueable Apex ?

This is combination of Batch & Future jobs.

Code Implementation  for a particular Account update the contact FirstName :


Queueable can be called from Batch ?

Yes,It can be called from Batch execute method.
Note : Only one enqueueJob call per execute

Ex:


Batch job can be called from Queueable ?

Yes,It's possible

Queueable can be called from Future methods?

No,It's not allowed

Future methods can be called from Queueable ?

Yes,It's possible

Queueable can be scheduled ?

Yes,It's allowed.

What are the features of Queueable over Future methods ?

1.Getting JobID 
2.Passing non-primitive types
3.Chaining Jobs

Queueable is super set of Future,So Future methods will be deprecated?

I don't think so,
Each one is designed for specific behavior.
Below are the cases where Future methods are more opt to use :
1.Future method is light weight and handy.
2.If we want a class to be synchronous and only some logic should be asynchronous.Marking method as future is easy.

Future methods are restricted to primitive datatypes,Because Objects could potentially change from the time it's passed to the time when the future method executes,Why this will not apply to Queueable Apex?

Ideally should avoid passing in entire Sobjects,Especially if they may change between serialization and execution.



Tuesday 12 December 2017

Batch Apex - Iterable

Syntax : global (Database.QueryLocator | Iterable) start(Database.BatchableContext bc) {}
When do we use Iterable ?
When some thing is not achieved by direct SOQL .
1. Aggregate queries in Batch Apex
2. Querying on multiple object
3. To process CSV / XML files
Refer SF Knowledge Article:
Sample Code :


Batch Apex - Call Out

What is the Call Out limit from Batch Apex ?

As per latest the upper limit is 100

Any workaround to process more than 100 call outs ?

Database.executeBatch(new BatchClass(),100
Pass the scope parameter as 100,Which can split the batch execution into multiple batches

How to define the scope w.r.t the callouts?
In execute method you have 2 call outs ,Your batch size should be 100/2 = 50
execute method has N callouts your batch size should be 100/N

Which interface need to use to implement call out from Batch Apex?

Database.AllowCallouts

What happens if we don't implement this interface and try to do call out ?
First error: Too many callouts: 1



Which type of call outs are allowed ?

HTTP request as well as methods defined with  web service key word .

Call Outs are allowed from Start /Finish methods?
Yes,Its possible 

REST API Call from Batch Apex :



Modify the standard object field label

Please find the below steps to modify the standard object field label.
Ex: Modify Contact Phone to Landline
Click on the Next button to rename the field label
Rename the field label as per requirement



Monday 11 December 2017

Batch Apex - Detect failed record Id's in Execute() method

Email notification of failed records from Execute /  Finish methods ?

We can send from any of the method.But ideal way is to send from Finish method.

Why its recommended to send notifications from Finish method ?

This finish method called after all batches are processed,It means only one time execution for complete job.

What is the use of  Database.Stateful ?
Batch Apex is by default Stateless.
To maintain the state across all transactions we can implement this interface 'Database.Stateful'.
Ex:
Capturing the failed record information in Execute method between all transactions and assigning to member. And use that member in Finish method.

Note : Only instance member variable retain their values between transaction.

Ex: Static member ,Which will not retain value between transaction.

The final o/p doesn't have any values captured.For the static member.



Sample code to find the failed records of Batch Apex  & Used Member variable to maintain the state