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
Irish@accIrish@acc 

Concat current months vs previous month in the Apex code..need help

Hi,

 

I have a scheduler class which create child records and this apex class fires on 1st day of every months...

I want to concat the name of the child record to concat with previous month vs current months...

 

so basically it should appear like this: childName= test-JAN-FEB;

 

please help me on this as how i Can achieve this..

Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi Irish,

 

I think you want to set childName as test-PreviousMonthName-CurrentMonthName

 

you can use following code in your class for this requirment.

 

string cmonthname,pmonthname;

 

if(MONTH(date.today())==1){

     cmonthname = JAN;

     pmonthname = DEC;

}

else if(MONTH(date.today())==2){     

     cmonthname = FEB;

     pmonthname = JAN;

}

else if(MONTH(date.today())==2){     

     cmonthname = FEB;

     pmonthname = JAN;

} 

else if(MONTH(date.today())==3){     

     cmonthname = MAR;

     pmonthname = FEB;

} 

else if(MONTH(date.today())==4){     

     cmonthname = APR;

     pmonthname = MAR;

}

else if(MONTH(date.today())==5){     

     cmonthname = MAY;

     pmonthname = APR;

} 

else if(MONTH(date.today())==6){     

     cmonthname = JUN;

     pmonthname = MAY;

} 

else if(MONTH(date.today())==7){     

     cmonthname = JUL;

     pmonthname = JUN;

} 

else if(MONTH(date.today())==8){     

     cmonthname = AUG;

     pmonthname = JUL;

} 

else if(MONTH(date.today())==9){     

     cmonthname = SEP;

     pmonthname = AUG;

} 

else if(MONTH(date.today())==10){     

     cmonthname = OCT;

     pmonthname = SEP;

} 

else if(MONTH(date.today())==11){     

     cmonthname = NOV;

     pmonthname = OCT;

} 

else if(MONTH(date.today())==12){     

     cmonthname = DEC;

     pmonthname = NOV;

}

 

if(cmonthname!=null && pmonthname!=null){

        childname = 'test-'+pmonthname=cmonthname;

}

 

When your scheduled class run then it calculates the current date month and set child name as per your requirement.

 

If this is you solution then mark it as a solution and others can take help for similar issues.