lundi 14 décembre 2015

Apex test class help - 90%

I am trying to deploy my apex trigger and test class its 90% in sandbox but won't go to production. I think i need to add a required field that is on opportunity object in my lead conversion trigger. I can't figure out where to add the field for opportunity in my test class. Trigger:

trigger accountContact on Lead (after update) {
if (trigger.isAfter && trigger.isUpdate) {
List<Opportunity> oppsToUpdate = new List<Opportunity>();
for (Lead ld : trigger.New) {
if(ld.isConverted && trigger.OldMap.get(ld.id).isConverted) {
continue;
}
if (ld.ConvertedOpportunityId != null && ld.ConvertedContactId != null) {
Opportunity opp = new Opportunity(Id = ld.ConvertedOpportunityId);
opp.Account_Contact__c = ld.ConvertedContactID;
oppsToUpdate.add(opp);
}
}
if (!oppsToUpdate.isEmpty()) {
update oppsToUpdate;
}
}
}

TEST CLASS:

@isTest
public class accountContactTestclass {
private static testMethod void myUnitTest() {
Lead l = new Lead(LastName='Doe', Firstname='John', Company='Test', Status='Converted', Type__c='Delegate',
Phone='6308888888',Title='CEO');
insert l;
database.LeadConvert lc = new database.LeadConvert();
lc.setLeadID(l.id);
lc.setDoNotCreateOpportunity(false);
test.startTest();
LeadStatus convertStatus=[SELECT Id, MasterLabel FROM LeadStatus WHERE isConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = database.convertLead(lc);
system.assert(lcr.isSuccess());
test.stopTest();
}
}

Aucun commentaire:

Enregistrer un commentaire