You need to sign in to do that
Don't have an account?
Srini
Help to create BatchJob
Hi Team,
We have a requirement to create batchapex. Mentioned the senario below.We have two fields(Checkboxes) are avalable in Opprtunity.
1.Last 30 days (Formula)
2.Last 30 Days (Workflow)
3.Last 730 days (Formula)
4.Last 730 Days (Workflow)
Hear If Formula field(Last 30 days)is true then workflow field(Last 30 Days) automatically should be true ,Similorly same to Last 730 days(Formula)is true it should be true for Last 730 Days (Workflow). Can any one please help us to create batch apex for the above requirement.
Thanks in Advance
We have a requirement to create batchapex. Mentioned the senario below.We have two fields(Checkboxes) are avalable in Opprtunity.
1.Last 30 days (Formula)
2.Last 30 Days (Workflow)
3.Last 730 days (Formula)
4.Last 730 Days (Workflow)
Hear If Formula field(Last 30 days)is true then workflow field(Last 30 Days) automatically should be true ,Similorly same to Last 730 days(Formula)is true it should be true for Last 730 Days (Workflow). Can any one please help us to create batch apex for the above requirement.
Thanks in Advance
All Answers
to avoid double checking both the conditions.
Thanks for your quick reply. I have tried with your logic.showing errors like "Variable does not exist: CW_in_Last_30_Days_Formula__c at line 10 column 16".
Please check below code which we are tried. And also this is only applicable for Closed Opportunity.
global class OpportunityCWDays implements Database.Batchable<Sobject>{
global OpportunityCWDays(){
}
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'Select id,CW_in_Last_30_Days_Formula__c,CW_in_Last_30_Days_Workflow__c,CW_in_Last_730_Days_Formula__c,CW_in_Last_730_Days_Workflow__c from Opportunity Where CW_in_Last_30_Days_Formula__c = True';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<Opportunity> lstOpp){
for(Opportunity objOpp : lstOpp){
if(CW_in_Last_30_Days_Formula__c) //Error line
objOpp.CW_in_Last_30_Days_Workflow__c = TRUE;
if(CW_in_Last_730_Days_Formula__c)
objOpp.CW_in_Last_730_Days_Workflow__c = TRUE;
}
update lstOpp;
}
global void finish(Database.BatchableContext BC){
}
}
Thanks
Thanks for your help...I will check and let you know. If any thing i have required.Sorry for the late response.
Thanks
Working as expected..Thanks
We are changed the Requirement now. Needs to be used two different SOQL : Please check the SOQL Which we are created.
1.Select id,StageName,Software_Product_Count__c,CW_in_Last_30_Days_Formula__c,CW_in_Last_30_Days_Workflow__c from Opportunity
Where Software_Product_Count__c > 0 AND
((CW_in_Last_30_Days_Formula__c = TRUE AND CW_in_Last_30_Days_Workflow__c = False) OR
(CW_in_Last_30_Days_Formula__c = False AND CW_in_Last_30_Days_Workflow__c = True))
2.Select id,StageName,Software_Product_Count__c,CW_in_Last_730_Days_Formula__c,CW_in_Last_730_Days_Workflow__c from Opportunity
Where Software_Product_Count__c > 0 AND
((CW_in_Last_730_Days_Formula__c = TRUE AND CW_in_Last_730_Days_Workflow__c = False) OR
(CW_in_Last_730_Days_Formula__c = False AND CW_in_Last_730_Days_Workflow__c = True))
Can you please modify the above code according to current senario.that would be great help.
Thanks
- 2 queries means 2 batches you want to write?
- What you want to do on the logic part based on this query?
1.We don't want to create two batches.
2. A)CW_in_Last_30_Days_Formula__c = False AND CW_in_Last_30_Days_Workflow__c = True then should be CW_in_Last_30_Days_Workflow__c = False.
B).CW_in_Last_30_Days_Formula__c = True AND CW_in_Last_30_Days_Workflow__c = False then should be CW_in_Last_30_Days_Workflow__c = True.
Similorly it will applicable for 730 days as well.Is there any possibilty to including one query as mentioend above senario?
Please find below code which is working.
global class OpportunityCWDays implements Database.Batchable<Sobject>{
global OpportunityCWDays(){
}
global Database.QueryLocator start(Database.BatchableContext BC){
Id idOpp = 'xxxxxxxxxxx';
String query = 'Select id, StageName, Software_Product_Count__c, CW_in_Last_30_Days_Formula__c, CW_in_Last_30_Days_Workflow__c, CW_in_Last_730_Days_Formula__c, CW_in_Last_730_Days_Workflow__c from Opportunity WHERE Id =:idOpp' ;
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<Opportunity> lstOpp){
for(Opportunity objOpp : lstOpp){
if(objOpp.CW_in_Last_30_Days_Formula__c == True) {
objOpp.CW_in_Last_30_Days_Workflow__c = TRUE;
}
else {
objOpp.CW_in_Last_30_Days_Workflow__c = False;
}
if(objOpp.CW_in_Last_730_Days_Formula__c == True) {
objOpp.CW_in_Last_730_Days_Workflow__c = True;
}
else {
objOpp.CW_in_Last_730_Days_Workflow__c = False;
}
}
update lstOpp;
}
global void finish(Database.BatchableContext BC){
}
}
Thanks