checkRecursive

public with sharing class checkRecursive {
   private static boolean run = true;
 

    public static boolean runOnce()
{
   if(run)
    {
     run=false;
     return true;
    }
    else
    {
        return run;
    }
   }
}

Create Single Linked List

Node Definition:

public class W
{
public class NodeDef
    {
     public Contact Value=new Contact();
     public NodeDef Ref;
    }

 public class SingleLinkedList
    {
     public NodeDef InitNode;
     public NodeDef NextNode;
 
    }
}




Create Single Linked List:
public class Util
{
public static W.SingleLinkedList getContactInSingleLinkedList()
{
  w.SingleLinkedList objSLL=new w.SingleLinkedList();
  List<Contact> lstContact=[Select Name from Contact];
  for(Contact objContact :lstContact)
  {
    if(objSLL.InitNode==null)
    {
    objSLL.InitNode=new W.NodeDef();
    objSLL.InitNode.Value=objContact;
    objSLL.InitNode.Ref=null;
    }
    else if(objSLL.NextNode==null)
    {
    objSLL.NextNode=new w.NodeDef();
    objSLL.NextNode.Value=objContact;
    objSLL.NextNode.Ref=Null;
    objSLL.InitNode.Ref=objSLL.NextNode;
    }
    else
    {
    w.NodeDef n=new w.NodeDef();
    n.Value=objContact;
    n.Ref=Null;
    objSLL.NextNode.Ref=n;
    objSLL.NextNode=n;
    }
  }
return objSLL;
}
}

Counters