You need to sign in to do that
Don't have an account?
Vidya H 4
hi please helpp me to write test class for this batch class
global class UpdateFunding implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
}
global void execute(Database.BatchableContext context, List<sObject> batch){
Set<Id> Opportuniyids = new Set<Id>();
for (sObject oppy : batch) {
Opportuniyids.add(oppy.Id);
}
updatequote(Opportuniyids);
}
global void finish(Database.BatchableContext context) {}
public void updatequote(set<id> oppyids){
system.debug('opportuiy ids'+oppyids);
List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
for(Opportunity opp:opportunities) {
Set<String> systems = new Set<String>();
for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
if (String.isNotBlank(oppObj.Funding__c)) {
systems.addAll(oppObj.Funding__c.split(';'));
}
}
String accountSystems = '';
for (String value : systems) {
accountSystems += value + ';';
}
accountSystems = accountSystems.removeEnd(';');
try {
update new Opportunity(Id = opp.id,Funding__c = accountSystems);
} catch (Exception e) {
System.debug('Exception: ' + e.getMessage());
}
}
}
}
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
}
global void execute(Database.BatchableContext context, List<sObject> batch){
Set<Id> Opportuniyids = new Set<Id>();
for (sObject oppy : batch) {
Opportuniyids.add(oppy.Id);
}
updatequote(Opportuniyids);
}
global void finish(Database.BatchableContext context) {}
public void updatequote(set<id> oppyids){
system.debug('opportuiy ids'+oppyids);
List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
for(Opportunity opp:opportunities) {
Set<String> systems = new Set<String>();
for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
if (String.isNotBlank(oppObj.Funding__c)) {
systems.addAll(oppObj.Funding__c.split(';'));
}
}
String accountSystems = '';
for (String value : systems) {
accountSystems += value + ';';
}
accountSystems = accountSystems.removeEnd(';');
try {
update new Opportunity(Id = opp.id,Funding__c = accountSystems);
} catch (Exception e) {
System.debug('Exception: ' + e.getMessage());
}
}
}
}
Can you try the below test class.
If this solution helps, Please mark it as best answer.
Thanks,
Try Below Test Class Please Mark It As Best Asnwer If It Helps
Thank You!
@CharuDutt
need to test for negetive scenario also