Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Apex Code Coverage
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Apex Code Coverage
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-14-2012 10:46 AM
We have an issue where a Unit Test keeps failing and only reaching 37% cover.
When I look at the trigger with 37% coverage and see where the issue lies, below is what I get where the error is in red. I'm not sure how to fix this, and I was hoping someone could please help me on what I need to do to get this coverage up because it's already in our production system, and we can't load any new coding in because the validation fails as a result of the error here.
Any help or direction on this would be GREATLY appreciated.
Thank you!
| Code Coverage | Help for this Page![]() |
LeadConversionTrigger (Code Covered: 37%)
| line | source |
| 1 | trigger LeadConversionTrigger on Lead (after update) { |
| 2 | |
| 3 | // loop over all leads being updated |
| 4 | Integer i; |
| 5 | for(i=0; i<Trigger.new.size(); i++) { |
| 6 | |
| 7 | // check if this is a conversion |
| 8 | if (Trigger.old[i].isConverted == false && Trigger.new[i].isConverted == true) { |
| 9 | |
| 10 | // if a new opportunity was created |
| 11 | if (Trigger.new[i].ConvertedOpportunityId != null) { |
| 12 | |
| 13 | // update the converted opportunity with some fields from the lead |
| 14 | Opportunity opp = [Select o.Id, o.Amount, o.Note_Box__c from Opportunity o Where o.Id = :Trigger.new[i].ConvertedOpportunityId]; |
| 15 | opp.Amount = Trigger.new[i].Amount__c; |
| 16 | opp.Note_Box__c = Trigger.new[i].Note_Box__c; |
| 17 | update opp; |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | } |
Re: Apex Code Coverage
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-14-2012 11:55 AM
Hi,
If this trigger is the problem, you cannot have much code in your SF instance.
Anyways, the problem is probably that your test code never enters this if-clause:
if (Trigger.old[i].isConverted == false && Trigger.new[i].isConverted == true) {
So what you need to do is to create testdata with these characteristics and then update or insert or what ever the trigger might trigger on.
HTH / Niklas


