Thursday 22 September 2016

Queueable Apex In Depth

The class which implements the Queueable Interface are basically called as Queueable apex class .
The interface has only one method execute which takes the parameter of QueableContext which has one method.

Below are the  classes and methods related to Queueable Apex

A.Queueable (Interface)
   1.public void execute(QueueableContext context)
B.QueableContext (Interface)
   2.public ID getJobId()

C.Limit(Class)
1.public static Integer getLimitQueueableJobs()
2public static Integer getQueueableJobs()

D.System(Class)

  1.public static Boolean isQueueable()
  2.public static ID enqueueJob(Object queueableObj)

Examples :

public class QueueableClass implements Queueable { 
    public void execute(QueueableContext context) {
        // TODO
    }

}


Queueable Apex Limits:

1.You can add up to 50 jobs to the queue with System.enqueueJob in a single transaction. 
2.Limits.getQueueableJobs() helps to check how many queueable jobs have been added in one transaction
3.No limit is enforced on the depth of chained jobs, which means that you can chain one job to another job and repeat this. 
4.Can add only one job from an executing job with System.enqueueJob, means that only child job can exist for parent queueable job
5.For Developer Edition and Trial organizations, the maximum stack depth for chained jobs is 5 .


Friday 19 August 2016

Integration/webservice Concepts

I saw people in industry are really crazy to learn Integration .Real thing is that integration is not a rocket science kind of thing .
In my view a developer who is logically good he will definitely good in integration .

Lets discuss about integration/web service .

Web service basically are of  two  types :
1.SOAP(Simple Object Access Protocol)

2.REST (Representational State Transfer

I know every body have  at least  idea about above two types of we service.

Again in each we can have Inbound and Outbound web service .

Lets discuss what is inbound and outbound web service . 

When we are writing a service for other and for us it is Inbound and for Other it is outbound web service .

Same way when we are consuming other's service then for us it is outbound and for them it is inbound web service .

I think now we are clear, what is inbound and out bound web service .

Lets discus as a sales force developer  how we can write inbound web service  for others .

Inbound Web Service Using SOAP :

Here we will learn how to write a sample web service using SOAP and how we can test ,also how we can write test class for this .


To write a web service we need to write a apex class . 


  • Class should be global access specified .
  • Methods should be start with web service key word .
  • Any method that uses the Web Service keyword should  static  .
  • Return type should not Map,Set,Pattern Object, Matcher Object,Exception Object . 
  •  We cannot deprecate webService methods or variables in managed package 
Example 1:

Assume that we have written a web service  to get account name based on one external Id .

So while calling this web service  client needs to pass theexternal Id and in response it will return the name ,we can return other things as per our requirement .

global class AccountService{
    webservice static String getAccountName(String extid){
       if(extid != null){
        String accName=[SELECT Id,Name FROM Account WHERE APINameExtid =: extid LIMIT 1].Name;
        return accName;
       }
       return null;
    }
}
Replace APINameExtid with your external id Api name of field  created in Account .

Example 2 :