function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sruthi.458sruthi.458 

Apex code Coverage

Hi Friends,

I write a code for trigger and it has no errors also it works successfully but code coverage is 0%.

Can any one suggest for a solution.



trigger email on Lead (after insert) 
{
  string leadId = trigger.new[0].id;
  list<lead > lstlead =[select id,email from lead where id=:leadId];
  string leademail =lstlead[0].email;

     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setUseSignature(false);
    mail.setToAddresses(new String[] { leademail  });
    mail.setSubject('Document Email Demo');
    mail.setHtmlBody('Here is the email you requested');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  
}

Regards,
Srikanth

bob_buzzardbob_buzzard

Do you have a test class for this trigger, or any test class that inserts a lead?

 

If not, I'd start by taking a look at this wiki page on developerforce:

 

http://wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests

sruthi.458sruthi.458

Hi Bob_buzzard,

 

Can you post a test code for above Apex code;

 

Regards,

Srikanth

bob_buzzardbob_buzzard

It shouldn't be difficult - by the look of it you just need a test method that creates a lead containing an email address.  If you want to have a stab at it I'll help if you get stuck.