function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kondal Rao learnerKondal Rao learner 

Hi Regarding lead duration

HI Experts,

 

Actually my requirment is that when lead is created with the startdate and endate right so i will assign this lead to some other one so when owner changes of lead so i want to find the days , between this time slot i mean between first owner of lead to second owner of the lead so please guide me how to do that.

 

 

 

Thans in advance

 

 

 

 

 

ForceLoverForceLover

Hi Adithya,

 

You can achieve this using a trigger here i'm posting a sample code which will help you

 

 

trigger ownerchange on Lead (before update) {

   if(trigger.isUpdate){
  
      for(Lead Le:trigger.new){
     
          Lead oldLead=Trigger.oldmap.get(Le.id);
          System.Debug('@@@@@'+oldLead.OwnerId);
          if(Le.OwnerId!=oldLead.OwnerId){            
             DateTime Dt=System.now();
             System.Debug('@@'+Dt);
             integer numberofDaysDue =  Le.DOB__c.daysBetween(Le.doj__c);   ////////// You can replace these fields with which you want to know the difference say( Le.Stastdate__c.daysBetween(Dt))
             System.Debug('@@@@'+numberOfDaysDue );
         
          }
     
      }
  
   }

}

 

 

Please accept it as solution if it sloves your requirement