Find your content:

Search form

You are here

how to create a opportunity converted from lead in test class


I am writing a test class and need to create test data on an opportunity converted from a lead.

I can create a lead in test class

Lead testLead = new Lead();
testLead.FirstName = 'Test First';
testLead.LastName = 'Test Last';
testLead.Company = 'Test Co';
insert testLead;

But not sure how to convert it to an opportunity.

Attribution to: user481

Possible Suggestion/Solution #1

This is done using the convertLead operation. It is documented at

If you want to do it using a trigger, refer this blog post.

Attribution to: Gaurav Kheterpal
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content