I am writing test class for Rest service post method.i am covering code please help to cover code for this class. Test Class:

public class Leadconvert_Test {
    testmethod static void postlead(){
        lead l = new lead();
        l.firstname = 'test';
        l.lastname = 'user';
        l.email = 'test@user.com';
        l.company = 'welcome';
        insert l;
        account a = new account();
        a.name = 'welcome';
        insert a;
        contact c = new contact();
        c.firstname = 'test';
        c.lastname = 'user';
        c.email = 'test@user.com';
        c.accountid = a.id;
        insert c;     

Error: enter image description here

  • Are you getting any data in lead list ? – Muzammil Bajaria Apr 12 '17 at 14:40
  • Also specify which error you are facing. – Muzammil Bajaria Apr 12 '17 at 14:41
  • Thank you for responding..yes if lead exist with related parameters that lead will have in lead list. – hari P Apr 12 '17 at 14:42
  • i am not facing any error but code not covering 7% only covering help me how to cover code – hari P Apr 12 '17 at 14:43

I would go through the trailhead apex rest callouts module. It would be a good idea to add some mock HTML callouts. Follow the link below should take you to the trailhead module.

Apex REST Callouts Unit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.