You need to sign in to do that
Don't have an account?

hi all,am new to Test class ,kindly help me out
This is my code,
global class OpportunityInvoiceReport implements Database.Batchable<sObject>,Schedulable {
global void execute(SchedulableContext SC) {
Id batch = Database.executeBatch(new OpportunityInvoiceReport(),100);
}
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT Id,AccountId,Invoice_Number__c FROM Opportunity WHERE StageName = \'Implementation Complete (MED)\'';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Opportunity> scope){
Set<String> invoiceNumber = new Set<String>();
Map<String,Opportunity> oppMap = new Map<String,Opportunity>();
List<Opportunity_Invoices__c> oppInvoiceInsert = new List<Opportunity_Invoices__c>();
for(Opportunity opp:scope){
invoiceNumber.add(opp.Invoice_Number__c);
oppMap.put(opp.Invoice_Number__c,opp);
}
for(Invoice__c invoice:[SELECT Id,Name FROM Invoice__c WHERE Name =:invoiceNumber]){
Opportunity_Invoices__c oppInvoice = new Opportunity_Invoices__c();
oppInvoice.Invoice__c = invoice.Id;
oppInvoice.Account__c = oppMap.get(invoice.Name).AccountId;
oppInvoice.Opportunity__c = oppMap.get(invoice.Name).Id;
oppInvoiceInsert.add(oppInvoice);
}
insert oppInvoiceInsert;
}
global void finish(Database.BatchableContext BC){
System.debug('OpportunityInvoiceReport Batch Successfully COmpleted..!');
}
}
global class OpportunityInvoiceReport implements Database.Batchable<sObject>,Schedulable {
global void execute(SchedulableContext SC) {
Id batch = Database.executeBatch(new OpportunityInvoiceReport(),100);
}
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT Id,AccountId,Invoice_Number__c FROM Opportunity WHERE StageName = \'Implementation Complete (MED)\'';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Opportunity> scope){
Set<String> invoiceNumber = new Set<String>();
Map<String,Opportunity> oppMap = new Map<String,Opportunity>();
List<Opportunity_Invoices__c> oppInvoiceInsert = new List<Opportunity_Invoices__c>();
for(Opportunity opp:scope){
invoiceNumber.add(opp.Invoice_Number__c);
oppMap.put(opp.Invoice_Number__c,opp);
}
for(Invoice__c invoice:[SELECT Id,Name FROM Invoice__c WHERE Name =:invoiceNumber]){
Opportunity_Invoices__c oppInvoice = new Opportunity_Invoices__c();
oppInvoice.Invoice__c = invoice.Id;
oppInvoice.Account__c = oppMap.get(invoice.Name).AccountId;
oppInvoice.Opportunity__c = oppMap.get(invoice.Name).Id;
oppInvoiceInsert.add(oppInvoice);
}
insert oppInvoiceInsert;
}
global void finish(Database.BatchableContext BC){
System.debug('OpportunityInvoiceReport Batch Successfully COmpleted..!');
}
}
Try this code : I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
Try this: Please mark this as best anser if it helps.
Try this code : I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi