I have written a trigger ans test class. New to coding so could do with someone casting their eye over the test class as it doesn't seem to hit the 75% code coverage.
APEX TRIGGER
trigger CreateQuote on Opportunity (after insert) {
List<Id> oppIdsList = new List<Id>();
List<Quote> quoteList = new List<Quote>();
for (Opportunity o : Trigger.new) {
oppIdsList.add(o.id);
}
Opportunity[] oppList = [SELECT
name,
id,
account.billingStreet,
account.billingCity,
account.billingState,
account.billingCountry
FROM Opportunity
WHERE id IN :oppIdsList and Type = 'New Client'];
for (Opportunity o : oppList) {
Quote q = new Quote();
q.name = 'Quote-' + o.name;
q.opportunityId = o.id;
q.billingStreet = o.account.billingStreet;
q.billingCity = o.account.billingCity;
q.billingState = o.account.billingState;
q.billingCountry = o.account.billingCountry;
quoteList.add(q);
}
insert quoteList;
}
My Test Class
@isTest
public class TestCreateQuote
{
Static testMethod void TestCreateQuote(){
Account a = [select Id from Account limit 1];
Opportunity o = new Opportunity();
o.Accountid = a.id;
o.Name = 'test';
o.StageName = 'Prospecting';
o.CloseDate = date.today();
o.Project_Type_test__c = 'Training';
o.Remuneration_Model__c = 'Fees Only';
o.Type = 'New Client';
o.NextStep = 'Test';
o.LeadSource = 'Business Development';
insert o;
}
}
Result of the test: