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
- :
- Re: Test Coverage 93% how to Make this code cover ...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Test Coverage 93% how to Make this code cover to 100%
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 03:07 AM - edited 11-15-2012 03:08 AM
error for these red lines plz help me to sort it out
public class TriggerClass {
public void Mycodecoverage(Branch__c Mycodecoverage)
{
string BankId = Mycodecoverage.Project_Bank__c;
List<Bank__c> bank = [select id,project__c,project__r.name,bank_Description__c from Bank__c where id =: BankId];
string BankName = bank[0].Project__r.name;
system.debug('---> Project Name --->'+BankName);
string bankDescription = bank[0].bank_Description__c;
string MycodecoverageComment = Mycodecoverage.Comment__c;
system.debug('---> bank Update Comment --->'+MycodecoverageComment);
List<Bank__c> banklist = [select id,name,bank_Description__c,bank_Owner__c,bank_Own
String bankOwnerEmail = '';
String bankOwnerId = '';
if(banklist.size()>0 && banklist[0].bank_Owner__c != null && banklist[0].bank_Owner__r.email != null)
{
bankOwnerEmail = banklist[0].bank_Owner__r.email;
bankOwnerId = banklist[0].bank_Owner__c;
}
String currentOwnerId = UserInfo.getUserId();
List<User> user = [select id,name,email from User where id =: currentOwnerId];
String currentownerEmail = user[0].Email;
List<String> Emails = new List<String>();
Emails.add(bankOwnerEmail);
if(bankOwnerId != currentOwnerId){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = Emails;
mail.setToAddresses(toAddresses);
mail.setBccSender(true);
mail.setUseSignature(false);
String Esubject = bankDescription + '/' + BankName;
mail.setSubject(Esubject);
mail.setPlainTextBody(MycodecoverageComment);
mail.saveAsActivity=false;
mail.setTargetObjectId (UserInfo.getUserId());
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
@isTest
private static void TriggerClass()
{
trg_TriggerClass branchClass= new TriggerClass ();
Account account = new Account();
account.name = 'test account';
try{
insert account;
}
catch(exception e){}
system.assertnotequals(account ,null);
Project__c project = new Project__c();
project.name = 'test project';
project.Account__c = account.id;
try{
insert project;
}
catch(exception e){}
system.assertnotequals(project,null);
//String currentOwnerId = UserInfo.getUserId(); (if i remove the comment for this )
Bank__c TestBank= new Bank__c();
TestBank.Name = 'test branch';
TestBank.Project__c = project.Id;
TestBank.branch_Description__c = 'test';
//TestBank.branch_Owner__c = currentOwnerId; (and remove comment for this then two red lines are covering but Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); to--------- Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } is not covering )
try{
insert TestBank;
}
catch(exception e){}
system.assertnotequals(TestBank,null);
Branch__C branch= new Branch__C();
branch.Project_Bank__c= TestBank.Id;
branch.Make_Public__c = true ;
branch.Comment__c = '';
try
{
insert branch;
}
catch(exception e){}
system.assertnotequals(branch,null );
}
}
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 03:41 AM
Hi,
Remove the above commented line and change the TestBank.branch_Owner__c to some other id (Not the currentOwnerId).
EX:
String currentOwnerId = UserInfo.getUserId(); (Let it remain same)
TestBank.branch_Owner__c = 'Some other user id'; (Change the highligted text with the other user id )
This should do it.
Regards,
Manjunath
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 03:45 AM
Hi
Remove that comment... and add some line like this...In your test class
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId (currentOwnerId);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Did this post Answers your questions ...if so please mark it as solved..
Thanks
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 03:46 AM
Hi Manjunath thanks for the reply, I changed the to some thing like '00790000001wKVj' but there is no change in it
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 04:09 AM
Hi Asish, I tried the code but there is not in it . I wrote the trigger in class class coverage is showing as 63% but trigger coverage is showing as 100%
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 04:29 AM
Hi,
Before inserting the TestBank add email to this object in your test class.
Regards,
Manjunath
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 04:39 AM
In this case i getting the error as
Invalid field Email for SObject Bank__c
Re: Test Coverage 93% how to Make this code cover to 100%
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 04:51 AM - edited 11-15-2012 05:08 AM
Hi,
Try this TestBank.bank_Owner__r.email='abc@abc.com';
Regards,
Manjunath
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 05:45 AM
Hi,
Try this TestBank.bank_Owner__r.email='abc@abc.com';
its not working 0%
Re: Test Coverage 93% how to Make this code cover to 100%
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 10:38 AM
I'd be more worried about the fact that your code isn't bulkified rather than a 7% coverage that might not even be necessary once you fix your code.
~ sfdcfox ~
I am a sandwich. That is all.

