You need to sign in to do that
Don't have an account?
Chidanand 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)
{
Oppnames.add(opp.Name);
}
MapAccwithOpps.put(a.Name,Oppnames);
}
system.debug('MapAccwithOpps==='+MapAccwithOpps);
for(Account a:AllAccounts)
{
Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
if(numberDaysDue<=60)
{
Opportunity O= new Opportunity();
o.Name=a.Name;
o.StageName='Legal';
o.Amount=a.ARR__c;
o.AccountId=a.ID;
o.CloseDate=Date.today();
o.NextStep='Won';
if(!(MapAccwithOpps.get(a.Name).contains(o.Name)))
insert o;
}
system.debug('Diff==='+numberDaysDue);
}
How to create a scheduled job for this. I want to run this code every day Automatically.
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)
{
Oppnames.add(opp.Name);
}
MapAccwithOpps.put(a.Name,Oppnames);
}
system.debug('MapAccwithOpps==='+MapAccwithOpps);
for(Account a:AllAccounts)
{
Integer numberDaysDue= a.Relationship_Start_Date__c.daysBetween(d);
if(numberDaysDue<=60)
{
Opportunity O= new Opportunity();
o.Name=a.Name;
o.StageName='Legal';
o.Amount=a.ARR__c;
o.AccountId=a.ID;
o.CloseDate=Date.today();
o.NextStep='Won';
if(!(MapAccwithOpps.get(a.Name).contains(o.Name)))
insert o;
}
system.debug('Diff==='+numberDaysDue);
}
How to create a scheduled job for this. I want to run this code every day Automatically.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
https://help.salesforce.com/HTViewHelpDoc?id=code_schedule_batch_apex.htm&language=en_US
First you need to need created a schedulable class,
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
The above schedule logic will run everyday at 1PM, change 13 if you want to schedule in different time.