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
Chidanand Magadum 24Chidanand Magadum 24 

How to create a Scheculed job

HI all,

This is my code
Date d = Date.Today();
 List<Account> AllAccounts= new List<Account>([select id,Name,Relationship_Start_Date__c,ARR__c,(Select Name from Opportunities) from Account ]);
 Map<String,Set<String>> MapAccwithOpps =new Map<String,Set<String>>();
 for(Account a:AllAccounts)
 Set<String> Oppnames = new Set<String>();
    //string Oppnames='';
    for(Opportunity opp:a.Opportunities)
 for(Account a:AllAccounts)
    Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
    Opportunity O= new Opportunity();
        insert o;

How to create a scheduled job for this. I want to run this code every day Automatically.
Yogesh KulkarniYogesh Kulkarni
Check these URLs

Arunkumar RArunkumar R

First you need to need created a schedulable class,
global class ScheduleLogic implements Schedulable {
   global void execute(SchedulableContext SC) {
// add your code logic.

Then you can schedule a job using developer console or you can click schedule Apex button after schedule class is save and give your prefered time and date.

Go to developer console --> Press Ctrl + E, then paste the below code, click execute
ScheduleLogic m = new ScheduleLogic();
String sch = '0 0 13 * * ?';
String jobID = system.schedule('Merge Job', sch, m);

The above schedule logic will run everyday at 1PM, change 13 if you want to schedule in different time.