You need to sign in to do that
Don't have an account?
kaushik Krishnan 15
write a test class for invocable method
Hi,
I am facing an issue for writing a test class for a invocable method which is getting called by Process Builder.
Actual class--
public class vOppDuplicate {
//public virtual class BaseException extends Exception {}
//public class OtherException extends BaseException {}
@InvocableMethod (label='Records for duplicate' description='Duplicate Check')
public static void updateOppDup(List<Id> OpportunityIds) {
try{
List<Opportunity> oppList = [SELECT Opp_Acc_Concatenate__c,Opportunity_Unique_Name__c FROM Opportunity WHERE Id in :OpportunityIds];
for(Opportunity opp: oppList)
{
opp.Opportunity_Unique_Name__c = opp.Opp_Acc_Concatenate__c;
}
update oppList;
//return oppList;
}
catch(DMLException e)
{
//throw new OtherException('Duplicate value is present');
throw new DMLException('Duplicate value with same opportunity and account name already present.'+'<br/>');
//System.debug('The following exception has occurred: ' + e.getMessage());
//if(e.getMessage().contains('Update failed')){
//e.setMessage('Duplicate value is already present.');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, e.getMessage()));
//}
}
}
}
Test Class---
@isTest
private class vOppDuplicateTest {
@isTest static void testdup() {
Account acc = new Account(name='TestClient');
insert acc;
Opportunity oppList = new Opportunity(Opportunity_Unique_Name__c= 'DupAccOppTest', Name = 'OppDup',AccountId=acc.Id);
insert oppList;
//oppList = [SELECT Id from Opportunity where Id = : oppList.Id];
vOppDuplicate oppdup = new vOppDuplicate();
//oppdup.updateOppDup();
}
}
How do i call the method and pass the value ?
Thanks
I am facing an issue for writing a test class for a invocable method which is getting called by Process Builder.
Actual class--
public class vOppDuplicate {
//public virtual class BaseException extends Exception {}
//public class OtherException extends BaseException {}
@InvocableMethod (label='Records for duplicate' description='Duplicate Check')
public static void updateOppDup(List<Id> OpportunityIds) {
try{
List<Opportunity> oppList = [SELECT Opp_Acc_Concatenate__c,Opportunity_Unique_Name__c FROM Opportunity WHERE Id in :OpportunityIds];
for(Opportunity opp: oppList)
{
opp.Opportunity_Unique_Name__c = opp.Opp_Acc_Concatenate__c;
}
update oppList;
//return oppList;
}
catch(DMLException e)
{
//throw new OtherException('Duplicate value is present');
throw new DMLException('Duplicate value with same opportunity and account name already present.'+'<br/>');
//System.debug('The following exception has occurred: ' + e.getMessage());
//if(e.getMessage().contains('Update failed')){
//e.setMessage('Duplicate value is already present.');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, e.getMessage()));
//}
}
}
}
Test Class---
@isTest
private class vOppDuplicateTest {
@isTest static void testdup() {
Account acc = new Account(name='TestClient');
insert acc;
Opportunity oppList = new Opportunity(Opportunity_Unique_Name__c= 'DupAccOppTest', Name = 'OppDup',AccountId=acc.Id);
insert oppList;
//oppList = [SELECT Id from Opportunity where Id = : oppList.Id];
vOppDuplicate oppdup = new vOppDuplicate();
//oppdup.updateOppDup();
}
}
How do i call the method and pass the value ?
Thanks
You should also use assert to validate your code is working fine.
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/
All Answers
You should also use assert to validate your code is working fine.
If this answer helps you, please mark it as accepted.
Regards,
Tushar Sharma
https://newstechnologystuff.com/
Regards,
Kaushik