I have a Trigger that creates a record in a custom object ("Services__c") when an Opportunity is marked as "Closed Won". Once closed won, a new Service record will be inserted, and:
- Service Record Type will be set based on information provided in the Opportunity
- Opportunity Team Members will be pulled into the Service record
- Some fields in the Service record will be pre-populated
The trigger works perfectly, but I am having trouble writing an APEX class/test method to promote it to Production! Can anyone help point out my issue? I am getting the error: "Constructors Can not be static"
HERE IS THE TRIGGER
trigger ServiceCreation on Opportunity (after update) {
map<id,Opportunity> oldValueMap = Trigger.oldMap;
FOR(OPPORTUNITY OPP:TRIGGER.NEW){
Opportunity oldOpp = oldValueMap.get(OPP.id);
//Check if Opportunity is Won, is a Centinel Integration, and is not marked as a Plan Upgrade
if (OPP.isWon && !oldOpp.isWon && Opp.Platform__c <>'Cardinal 2ID' && Opp.Type<>'Plan Upgrade'){
Services__c SVC = new Services__c();
//Queries Opportunity Team Member Table, returns list of User IDs and Team Member Roles
for(OpportunityTeamMember teamMember:[select UserID,TeamMemberRole from OpportunityTeamMember where OpportunityId=:OPP.ID]){
//Sets Service Owner and Client Manager in Service record based on Opportunity Team Members
if (teamMember.TeamMemberRole=='Activation Manager'){
SVC.OwnerId = teammember.userId;
} else if (teamMember.TeamMemberRole=='Client Manager'){
SVC.Client_Manager__c = teammember.userId;
}
}
//Queries Service Record Types and Developer Names
Map<string,id> serviceRTMap = new Map<string,id>();
for (RecordType RT:[select id,developerName from RecordType where SobjectType='Services__c']){
serviceRTMap.put(rt.developerName,rt.id);
}
//Set record type of Service based on Opportunity Information
if (opp.Product__c=='Consumer Authentication'){
Svc.RecordTypeId = serviceRTMap.get('Authentication');
} else if (opp.Product__c == 'Payment Brands' && opp.Payment_Brands__c.contains('PayPal')){
Svc.RecordTypeId = serviceRTMap.get('PayPal');
} else {
Svc.RecordTypeId = serviceRTMap.get('Payment_Brand');
}
//Prefill subset of Service fields, upon creation, with data from the Opportunity
Svc.Name = Opp.Name;
Svc.Register_Date__c = Opp.CloseDate;
Svc.Stage__c = '1-Boarding';
Svc.Status__c = 'Registered';
Svc.Related_Opportunity__c = Opp.ID;
svc.account__c = Opp.AccountID;
svc.Sales_Rep__c = Opp.OwnerID;
svc.Platform__c = Opp.Platform__c;
svc.Product__c = Opp.Product__c;
svc.Payment_Brand__c = Opp.Payment_Brands__c;
svc.Partner__c = Opp.Partner__c;
svc.Monthly_Transactions__c = Opp.Monthly_Transactions__c;
svc.Monthly_Revenue__c = Opp.Monthly_Revenue__c;
svc.Set_Up_Fee__c = Opp.Set_up_Fee__c;
svc.Annualized_Revenue__c = Opp.Amount;
svc.RBA__c = opp.Rules__c;
svc.Adapter__c = Opp.Adapter__c;
svc.Projected_Activation_Date__c = Opp.Projected_Activation_Date__c;
Insert SVC;
}
}
}
HERE IS THE CLASS
Public class TestServiceCreation {
Static testMethod void verifyOpportunityInsert() {
//data preparation
Opportunity Opp = new Opportunity(
Name = 'Consumer Authentication Test',
StageName = 'Closed Won',
CloseDate = system.today(),
Type = 'New Business',
Platform__c = 'Cardinal Centinel',
Product__c = 'Consumer Authentication',
Payment_Brands__c = 'Verified by Visa',
Rules__c = 'Yes',
Monthly_Transactions__c = 150,
Monthly_Revenue__c = 250,
Set_up_Fee__c = 1500);
//Insert Opportunity
test.startTest();
insert Opp;
Test.stopTest();
//Verify the Opportunity was inserted, and update the Stage to Closed Won
Static testMethod void verifyOppInsertAndUpdate
List<Opportunity> insertedOpportunities = [SELECT Name, StageName, Type, Platform__c, Product__c, Payment_Brands__c, Rules__c, Monthly_Transactions__c, Monthly_Revenue__c, Set_Up_Fee__c FROM Opportunity WHERE Name = 'Consumer Authentication Test'];
Opp.StageName = 'Closed Won';
Test.startTest();
Update Opp;
Test.StopTest();
//Verify the Service was inserted, and fields were brought over
Static testMethod void verifyServiceCreation
List<Services__c> insertedServices__c;
Services__c SVC = [SELECT Name, Account__c, Related_Opportunity__c,Status__c, Stage__c, Platform__c, Product__c, Payment_Brand__c, Register_Date__c, RBA__c, Monthly_Transactions__c, Monthly_Revenue__c, Set_Up_Fee__c FROM Services__c];
System.assertEquals(SVC.Name, 'Consumer Authentication');
System.assertEquals(SVC.Account__c, Opp.AccountId);
System.assertEquals(SVC.Related_Opportunity__c, Opp.ID);
System.assertEquals(SVC.Register_Date__c, Opp.CloseDate);
System.assertEquals(SVC.Status__c, 'Registered');
System.assertEquals(SVC.Stage__c, '1-Boarding');
System.assertEquals(SVC.Platform__c, 'Cardinal Centinel');
System.assertEquals(SVC.Product__c, 'Consumer Authentication');
System.assertEquals(SVC.Payment_Brand__c, 'Verified by Visa');
System.assertEquals(SVC.Monthly_Transactions__c, 1500);
System.assertEquals(SVC.Monthly_Revenue__c, 250);
System.assertEquals(SVC.Set_Up_Fee__c, 1500);
System.assertEquals(SVC.RBA__c, 'Yes');
}
}