That line is define where clause of query. It says that it will retrieve only those Fulfillment History which have Fulfillment Status = 'Pending Request' And Fulfillment Type = 'Check'.
But it is Batch start method, we are updating only one record?
Please find below complete batch class.
global class SubmitChecksBatch implements Database.batchable<sObject>,Database.AllowsCallouts, Database.Stateful{
global Case cs; global List<Fulfillment_History__c> toUpdateFulfillment = new List<Fulfillment_History__c>(); global List<Webservice_Call_Result__c> callLogs = new List<Webservice_Call_Result__c>(); global List<Task> failedCalls = new List<Task>();
global Boolean exceptionOccurred = false; global String exceptionMessage; global String exceptionTypeName;
global Database.QueryLocator start(Database.BatchableContext info){ String query = 'Select Name, Case__c, Fulfillment_Type__c, Fulfillment_Workflow__c from Fulfillment_History__c'; query += ' where Fulfillment_Status__c = \'Pending Request\' and Fulfillment_Type__c in (\'Check\')'; if(UtilityClass.isBatchTestMethodExecution) query += ' order by createddate desc limit 1'; return Database.getQueryLocator(query); }
global void execute(Database.BatchableContext info, List<Fulfillment_History__c> toSubmitChecks){ try { schemasDatacontractOrg200407Telerx.ClientCredentials clientCred = UtilityClass.getClientCredentials(); tempuriOrg.BasicHttpBinding_ITlxCheckAndLetterProcessor processVar = new tempuriOrg.BasicHttpBinding_ITlxCheckAndLetterProcessor(); schemasDatacontractOrg200407Telerx.SubmitCheckResponse submitCheckResponse = new schemasDatacontractOrg200407Telerx.SubmitCheckResponse();
//Create the array of check requests schemasDatacontractOrg200407Telerx.ArrayOfCheckRequest chqReqArray = new schemasDatacontractOrg200407Telerx.ArrayOfCheckRequest(); chqReqArray.CheckRequest = new List<schemasDatacontractOrg200407Telerx.CheckRequest>();
Fulfillment_History__c fh = toSubmitChecks[0];
// Get the Case information from the Fulfillment History record Case[] cases = [Select CaseNumber, RecordTypeId, Job__c, Product__c, Current_Fulfillment_Status__c, Fulfillment_Date__c, Claim_Status__c, Disposition__c, OwnerId, Calculated_Rebate__c, MEC_Transaction__c, Tax_ID__c, Account.Name, Practice_Address__c, Practice_Address_2__c, Practice_City__c, Practice_State__c, Practice_Zip__c, Patient_First_Name__c, Patient_Last_Name__c, Patient_Claim_Address_1__c, Patient_Claim_Address_2__c, Patient_Claim_City__c, State_of_Residence__c, Patient_Claim_Zip__c, Primary_Insured_First_Name__c, Primary_Insured_Last_Name__c, Primary_Insured_Address_1__c, Primary_Insured_Address_2__c, Primary_Insured_City__c, Primary_Insured_State__c, Primary_Insured_Zip__c from Case where Id = :fh.Case__c];
// Get the corresponding Job information for the Check and Letter Service Codes Jobs__c[] clsCodes = [Select Check_And_Letter_Service_Program_Code__c, Check_Type_Code__c from Jobs__c where Id = :cs.Job__c];
// Create the Check Request to submit schemasDatacontractOrg200407Telerx.CheckRequest chqReqTemp = new schemasDatacontractOrg200407Telerx.CheckRequest();
// Set the address of the correct Fulfillment Workflow type if(fh.Fulfillment_Workflow__c == 'Provider'){ chqReqTemp.MailingAddressLine1 = cs.Practice_Address__c; chqReqTemp.MailingAddressLine2 = cs.Practice_Address_2__c; chqReqTemp.MailingAddressCity = cs.Practice_City__c; chqReqTemp.MailingAddressState = cs.Practice_State__c; chqReqTemp.MailingAddressPostalCode = cs.Practice_Zip__c; chqReqTemp.MailingName = cs.Account.Name; chqReqTemp.PayeeName = cs.Account.Name;
// Create the array of custom fields schemasDatacontractOrg200407Telerx.ArrayOfCustomField customFieldArray = new schemasDatacontractOrg200407Telerx.ArrayOfCustomField(); customFieldArray.CustomField = new List<schemasDatacontractOrg200407Telerx.CustomField>();
// Pass the MEC Transaction ID. If there is no MEC Transaction ID on the Case then pass the Case Number. if(cs.MEC_Transaction__c != null) customFieldArray.CustomField.add(UtilityClass.createCustomWebServiceField('MEC_Transaction__c', cs.MEC_Transaction__c)); else customFieldArray.CustomField.add(UtilityClass.createCustomWebServiceField('MEC_Transaction__c', cs.CaseNumber));
// Pass the Tax ID if provided if(cs.Tax_ID__c != null) customFieldArray.CustomField.add(UtilityClass.createCustomWebServiceField('Tax_ID__c', cs.Tax_ID__c));
// Add the check request to the array of check requests chqReqArray.CheckRequest.add(chqReqTemp);
// This is used for the test classes since the test classes should not call out to the web service if(UtilityClass.isBatchTestMethodExecution) { submitCheckResponse.ResponseText = 'Successful Call'; submitCheckResponse.ResponseCode = '000'; submitCheckResponse.TransactionID = '123456789'; } else { submitCheckResponse = processVar.submitChecks(clientCred, programCode, chqReqArray); }
// This is used for the test classes so we can test response codes other than '000' for creating a Task if(UtilityClass.isBatchTestMethodExecution) { submitCheckResponse.ResponseText = 'Failed Call'; submitCheckResponse.ResponseCode = '300'; submitCheckResponse.TransactionID = '123456789'; }
Yes, You are updating only one record of Fulfillment History in batch class. But only whenever the boolean variable "isBatchTestMethodExecution" in "UtilityClass" is true. otherwise batch will process all those records which met the criteria defined in WHERE clause.
They are using batch class because of other stuffs which is executing in "Execute" method of batch class. So In batch query it will retrieve only one record, but the other execution of apex method might have salesforce limitation, to overcome that limitation they are using batch class.
Below are the execution flow of "Execute" method of batch class.
- Upto line 12: Preparing object of other apex clasess to use webservice callout - At line 13: Getting case record which is related to fullfilment history record - At line 24: Retrieve JOB record which is related to case record - Upto line 85: It is preparing CheckRequest with its all attributes like Address attributes are setting ub based on Fulfillment_Workflow__c value - At line 88: Wherever "if(UtilityClass.isBatchTestMethodExecution) {" this line is used, it will not not execute at run time That condition is for cover apex code from test class, so here at run time it will go for else part(line 94). - At line 94: It looks like it is executing some webservice callout - At line 97: After complete webservice, it will assign case record field based on response code like if response code is - 000, then case fields will be updated line 98 to 102 - Then at last it will create Webservice_Call_Result__c record for manage history of webservice callout
That line is define where clause of query.
It says that it will retrieve only those Fulfillment History which have Fulfillment Status = 'Pending Request' And Fulfillment Type = 'Check'.
Thanks & Cheers,
Jigar(pateljb90@gmail.com)
Thanks for quick reply.
In 5th line it returns one record or records on that data?
As in your query string you have LIMIT 1 it will return one record only .
Thanks for your reply.
But it is Batch start method, we are updating only one record?
Please find below complete batch class.
global class SubmitChecksBatch implements Database.batchable<sObject>,Database.AllowsCallouts, Database.Stateful{
global Case cs;
global List<Fulfillment_History__c> toUpdateFulfillment = new List<Fulfillment_History__c>();
global List<Webservice_Call_Result__c> callLogs = new List<Webservice_Call_Result__c>();
global List<Task> failedCalls = new List<Task>();
global Boolean exceptionOccurred = false;
global String exceptionMessage;
global String exceptionTypeName;
global Database.QueryLocator start(Database.BatchableContext info){
String query = 'Select Name, Case__c, Fulfillment_Type__c, Fulfillment_Workflow__c from Fulfillment_History__c';
query += ' where Fulfillment_Status__c = \'Pending Request\' and Fulfillment_Type__c in (\'Check\')';
if(UtilityClass.isBatchTestMethodExecution)
query += ' order by createddate desc limit 1';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext info, List<Fulfillment_History__c> toSubmitChecks){
try {
schemasDatacontractOrg200407Telerx.ClientCredentials clientCred = UtilityClass.getClientCredentials();
tempuriOrg.BasicHttpBinding_ITlxCheckAndLetterProcessor processVar = new tempuriOrg.BasicHttpBinding_ITlxCheckAndLetterProcessor();
schemasDatacontractOrg200407Telerx.SubmitCheckResponse submitCheckResponse = new schemasDatacontractOrg200407Telerx.SubmitCheckResponse();
//Create the array of check requests
schemasDatacontractOrg200407Telerx.ArrayOfCheckRequest chqReqArray = new schemasDatacontractOrg200407Telerx.ArrayOfCheckRequest();
chqReqArray.CheckRequest = new List<schemasDatacontractOrg200407Telerx.CheckRequest>();
Fulfillment_History__c fh = toSubmitChecks[0];
// Get the Case information from the Fulfillment History record
Case[] cases = [Select CaseNumber, RecordTypeId, Job__c, Product__c, Current_Fulfillment_Status__c, Fulfillment_Date__c, Claim_Status__c, Disposition__c, OwnerId, Calculated_Rebate__c, MEC_Transaction__c, Tax_ID__c,
Account.Name, Practice_Address__c, Practice_Address_2__c, Practice_City__c, Practice_State__c, Practice_Zip__c,
Patient_First_Name__c, Patient_Last_Name__c, Patient_Claim_Address_1__c, Patient_Claim_Address_2__c, Patient_Claim_City__c, State_of_Residence__c, Patient_Claim_Zip__c,
Primary_Insured_First_Name__c, Primary_Insured_Last_Name__c, Primary_Insured_Address_1__c, Primary_Insured_Address_2__c, Primary_Insured_City__c, Primary_Insured_State__c, Primary_Insured_Zip__c from Case
where Id = :fh.Case__c];
cs = cases[0];
String programCode;
String caseTypeName;
// Get the corresponding Job information for the Check and Letter Service Codes
Jobs__c[] clsCodes = [Select Check_And_Letter_Service_Program_Code__c, Check_Type_Code__c from Jobs__c
where Id = :cs.Job__c];
Jobs__c clsCode = clsCodes[0];
programCode = clsCode.Check_And_Letter_Service_Program_Code__c;
// Create the Check Request to submit
schemasDatacontractOrg200407Telerx.CheckRequest chqReqTemp = new schemasDatacontractOrg200407Telerx.CheckRequest();
chqReqTemp.CheckRequestID = fh.Name;
chqReqTemp.CheckType = clsCode.Check_Type_Code__c;
chqReqTemp.CheckAmount = String.valueOf(cs.Calculated_Rebate__c);
// Set the address of the correct Fulfillment Workflow type
if(fh.Fulfillment_Workflow__c == 'Provider'){
chqReqTemp.MailingAddressLine1 = cs.Practice_Address__c;
chqReqTemp.MailingAddressLine2 = cs.Practice_Address_2__c;
chqReqTemp.MailingAddressCity = cs.Practice_City__c;
chqReqTemp.MailingAddressState = cs.Practice_State__c;
chqReqTemp.MailingAddressPostalCode = cs.Practice_Zip__c;
chqReqTemp.MailingName = cs.Account.Name;
chqReqTemp.PayeeName = cs.Account.Name;
// Create the array of custom fields
schemasDatacontractOrg200407Telerx.ArrayOfCustomField customFieldArray = new schemasDatacontractOrg200407Telerx.ArrayOfCustomField();
customFieldArray.CustomField = new List<schemasDatacontractOrg200407Telerx.CustomField>();
// Pass the MEC Transaction ID. If there is no MEC Transaction ID on the Case then pass the Case Number.
if(cs.MEC_Transaction__c != null)
customFieldArray.CustomField.add(UtilityClass.createCustomWebServiceField('MEC_Transaction__c', cs.MEC_Transaction__c));
else
customFieldArray.CustomField.add(UtilityClass.createCustomWebServiceField('MEC_Transaction__c', cs.CaseNumber));
// Pass the Tax ID if provided
if(cs.Tax_ID__c != null)
customFieldArray.CustomField.add(UtilityClass.createCustomWebServiceField('Tax_ID__c', cs.Tax_ID__c));
chqReqTemp.CustomFields = customFieldArray;
}
else if(fh.Fulfillment_Workflow__c == 'Primary Insured'){
chqReqTemp.MailingAddressLine1 = cs.Primary_Insured_Address_1__c;
chqReqTemp.MailingAddressLine2 = cs.Primary_Insured_Address_2__c;
chqReqTemp.MailingAddressCity = cs.Primary_Insured_City__c;
chqReqTemp.MailingAddressState = cs.Primary_Insured_State__c;
chqReqTemp.MailingAddressPostalCode = cs.Primary_Insured_Zip__c;
chqReqTemp.MailingName = cs.Primary_Insured_First_Name__c + ' ' + cs.Primary_Insured_Last_Name__c;
chqReqTemp.PayeeName = cs.Primary_Insured_First_Name__c + ' ' + cs.Primary_Insured_Last_Name__c;
}
else if(fh.Fulfillment_Workflow__c == 'Patient'){
chqReqTemp.MailingAddressLine1 = cs.Patient_Claim_Address_1__c;
chqReqTemp.MailingAddressLine2 = cs.Patient_Claim_Address_2__c;
chqReqTemp.MailingAddressCity = cs.Patient_Claim_City__c;
chqReqTemp.MailingAddressState = cs.State_of_Residence__c;
chqReqTemp.MailingAddressPostalCode = cs.Patient_Claim_Zip__c;
chqReqTemp.MailingName = cs.Patient_First_Name__c + ' ' + cs.Patient_Last_Name__c;
chqReqTemp.PayeeName = cs.Patient_First_Name__c + ' ' + cs.Patient_Last_Name__c;
}
// Add the check request to the array of check requests
chqReqArray.CheckRequest.add(chqReqTemp);
// This is used for the test classes since the test classes should not call out to the web service
if(UtilityClass.isBatchTestMethodExecution) {
submitCheckResponse.ResponseText = 'Successful Call';
submitCheckResponse.ResponseCode = '000';
submitCheckResponse.TransactionID = '123456789';
}
else {
submitCheckResponse = processVar.submitChecks(clientCred, programCode, chqReqArray);
}
if(submitCheckResponse.ResponseCode == '000') {
cs.Current_Fulfillment_Status__c = 'Requested';
cs.Fulfillment_Date__c = null;
fh.Fulfillment_Status__c = 'Requested';
fh.Date_Requested__c = datetime.now();
update cs;
toUpdateFulfillment.add(fh);
}
Webservice_Call_Result__c callLog = new Webservice_Call_Result__c();
callLog.Case__c = cs.Id;
callLog.Name = 'Submit Check';
callLog.Response_Text__c = submitCheckResponse.ResponseText;
callLog.Response_Code__c = submitCheckResponse.ResponseCode;
callLog.Transaction_Id__c = submitCheckResponse.TransactionID;
callLogs.add(callLog);
// This is used for the test classes so we can test response codes other than '000' for creating a Task
if(UtilityClass.isBatchTestMethodExecution) {
submitCheckResponse.ResponseText = 'Failed Call';
submitCheckResponse.ResponseCode = '300';
submitCheckResponse.TransactionID = '123456789';
}
if(submitCheckResponse.ResponseCode != '000') {
String taskDescription;
if(submitCheckResponse.ResponseText != null)
taskDescription += 'Response Text: ' + submitCheckResponse.ResponseText + '; ';
if(submitCheckResponse.ResponseCode != null)
taskDescription += 'Response Code: ' + submitCheckResponse.ResponseCode + '; ';
if(submitCheckResponse.TransactionID != null)
taskDescription += 'Transaction Id: ' + submitCheckResponse.TransactionID + '; ';
UtilityClass.sendExceptionEmail('SubmitChecksBatch', 'Error while submitting checks for CaseNumber ' + cs.CaseNumber + '. ' + taskDescription, 'Failed Web Service Call');
//Task tsk = UtilityClass.createTask(cs, 'Error while submitting check for the case. Please open a help desk ticket.', taskDescription, 'In Progress', 'High', 1, true);
//failedCalls.add(tsk);
}
}
catch(Exception ex) {
exceptionOccurred = true;
exceptionMessage = 'CaseNumber: ' + cs.CaseNumber + ' - ' + ex.getMessage();
exceptionTypeName = ex.getTypeName();
}
}
global void finish(Database.BatchableContext info){
if(toUpdateFulfillment.size() > 0)
update toUpdateFulfillment;
if(callLogs.size() > 0)
insert callLogs;
if(failedCalls.size() > 0)
insert failedCalls;
if(exceptionOccurred)
UtilityClass.sendExceptionEmail('Submit Check', exceptionMessage, exceptionTypeName);
}
}
Yes, It will return only one record, not more than one record because of LIMIT 1.
Thanks & Cheers,
Jigar(pateljb90@gmail.com)
If it update one record, why they are using batch class.
Yes, You are updating only one record of Fulfillment History in batch class. But only whenever the boolean variable "isBatchTestMethodExecution" in "UtilityClass" is true. otherwise batch will process all those records which met the criteria defined in WHERE clause.
Thanks & Cheers,
Jigar(pateljb90@gmail.com)
They are using batch class because of other stuffs which is executing in "Execute" method of batch class.
So In batch query it will retrieve only one record, but the other execution of apex method might have salesforce limitation, to overcome that limitation they are using batch class.
Thanks & Cheers,
Jigar(pateljb90@gmail.com)
Please explain me, what is happening in my batch class. I need information about my batch class.
Below are the execution flow of "Execute" method of batch class.
- Upto line 12: Preparing object of other apex clasess to use webservice callout
- At line 13: Getting case record which is related to fullfilment history record
- At line 24: Retrieve JOB record which is related to case record
- Upto line 85: It is preparing CheckRequest with its all attributes
like Address attributes are setting ub based on Fulfillment_Workflow__c value
- At line 88: Wherever "if(UtilityClass.isBatchTestMethodExecution) {" this line is used, it will not not execute at run time
That condition is for cover apex code from test class, so here at run time it will go for else part(line 94).
- At line 94: It looks like it is executing some webservice callout
- At line 97: After complete webservice, it will assign case record field based on response code
like if response code is - 000, then case fields will be updated line 98 to 102
- Then at last it will create Webservice_Call_Result__c record for manage history of webservice callout
Thanks & Cheers,
Jigar(pateljb90@gmail.com)