You need to sign in to do that
Don't have an account?
Mallareddy
how to write test class on Opportunity ?
public class TypeOfBusinessValidation{
public static void validate(List<Opportunity> newList){
List<Opportunity> oppList = new List<Opportunity>();
Id MSORecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Managed Sales Opportunity').getRecordTypeId();
Map<id,Opportunity> oppMap = new Map<id,Opportunity>();
for(Opportunity opp : newList){
oppMap.put(opp.id,opp);
}
List<OpportunityLineItem> oppLt=[Select id,Product2.Division__c,OpportunityId,Opportunity.Competitive_Status__c,Opportunity.Type_of_business1__c from OpportunityLineItem where Opportunity.RecordTypeId=:MSORecordTypeId and OpportunityId in :newList];
for(OpportunityLineItem oli: oppLt){
if(oppMap.get(oli.OpportunityId).Competitive_Status__c== 'Not Competitive' && oli.Product2.Division__c=='END USER COMPUTING'){
oppMap.get(oli.OpportunityId).addError('Type of Business should not be blank when Competitive status is NOT COMPETITIVE and Product Division is END USER COMPUTING');
}
}
}
}
public static void validate(List<Opportunity> newList){
List<Opportunity> oppList = new List<Opportunity>();
Id MSORecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Managed Sales Opportunity').getRecordTypeId();
Map<id,Opportunity> oppMap = new Map<id,Opportunity>();
for(Opportunity opp : newList){
oppMap.put(opp.id,opp);
}
List<OpportunityLineItem> oppLt=[Select id,Product2.Division__c,OpportunityId,Opportunity.Competitive_Status__c,Opportunity.Type_of_business1__c from OpportunityLineItem where Opportunity.RecordTypeId=:MSORecordTypeId and OpportunityId in :newList];
for(OpportunityLineItem oli: oppLt){
if(oppMap.get(oli.OpportunityId).Competitive_Status__c== 'Not Competitive' && oli.Product2.Division__c=='END USER COMPUTING'){
oppMap.get(oli.OpportunityId).addError('Type of Business should not be blank when Competitive status is NOT COMPETITIVE and Product Division is END USER COMPUTING');
}
}
}
}
Please check below post for test class example
1) http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html
2) https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
30 https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
Please check above postcode level example
Please check below post to learn about test classes in Salesforce
1) http://amitsalesforce.blogspot.in/search/label/Test%20Class
2) http://amitsalesforce.blogspot.in/2015/09/test-classes-with-istest.html
3) http://amitsalesforce.blogspot.in/2015/06/salesforce-testing-best-practice.html
Thanks
Mohd Rais