Wednesday, 18 January 2012

Test Class on trigger involved lead conversion


//When the lead is converted to account and contact then the cases under that lead carried to account and contact created from lead conversion

trigger leadtrig on Lead (after update) {
        list<Id> leadids = new list<Id>();
        for(Lead objLead:trigger.new){
                if(objLead.IsConverted)
                    leadids.add(objLead.id);
        }
        list<case> lstcase=[Select id from case where Lead__c in:leadids];
        List<Case> lstcasetoupdate = new List<case>();
        if(lstcase != null){
        for(Lead obj: trigger.new){
            if(obj.IsConverted){
                    for(case c: lstcase){
                    c.accountid = obj.convertedAccountid;
                    c.contactid = obj.convertedContactid;
                    c.Lead__c = null;
                    lstcasetoUpdate.add(c);
            }
          }
        }
        if(lstcasetoUpdate.size()>0){
                update lstcasetoUpdate;
                }
        }
     
}

================================Test class on Trigger involves lead conversion as above=================


@isTest
private class Testonleadtrig {
     private static Id leadId;
       static {
       
    Lead testLead = new Lead();
        testLead.FirstName = 'Test First';
        testLead.LastName = 'Test Last';
        testLead.Company = 'Test Co';
        testLead.npe01__Preferred_Phone__c='Home';
        testLead.Status='Untouched';
        testLead.Company='Appshark';
       
        insert testLead;
       
        leadId = testLead.Id;
   
      }
   
    static testMethod void Test_LeadConvert(){
    Test.startTest();
        Case csobj=new Case();
            csobj.Subject='Email';
            csobj.Status='New';
            csobj.Origin='Email';
            csobj.Lead__c=LeadId;
            insert csobj;
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(LeadId);
       
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
       
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
    Test.stopTest();
           
    }
 
 
}



31 comments:

  1. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
    Click here:
    angularjs training in tambaram
    Click here:
    angularjs6 Training in Chennai

    ReplyDelete
  2. Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.

    Click here:
    Microsoft azure training in tambaram
    Click here:
    Microsoft azure training in chennai

    ReplyDelete
  3. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.

    Blueprism training in Chennai

    Blueprism training in Bangalore

    Blueprism training in Pune

    Blueprism online training

    Blueprism training in tambaram

    ReplyDelete
  4. I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
    java training in tambaram | java training in velachery

    java training in omr | oracle training in chennai

    ReplyDelete
  5. This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb. This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 

    Data Science course in Chennai | Data science course in bangalore
    Data science course in pune | Data science online course
    Data Science Interview questions and answers | Python course in Kalyan nagar

    ReplyDelete
  6. Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    ReplyDelete
  7. It’s a shame you don’t have a donate button! I’d certainly donate to this brilliant blog! I suppose for now I’ll settle for book-marking and adding your RSS feed to my Google account.
    industrial safetyu courses in chennai

    ReplyDelete
  8. It’s great to come across a blog every once in a while, that isn’t the same out of date rehashed material. Fantastic read.

    Cloud Training
    Software Testing Training
    Oracle DBA Training
    Angular Training in Chennai

    ReplyDelete
  9. Nice and good post. This is a wonderful article, Given so much info in it, keep sharing.


    Data Science Bangalore

    ReplyDelete
  10. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on.
    Data Science Course in Pune

    ReplyDelete
  11. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    data science course

    ReplyDelete
  12. Assume paid for with the help of center, have discovered modern society; believed that protect on your playlists, you could potentially know most of the hassle; assumed ones step quit, much more is unable to drive; Imagine I would like adore, merely the caress. asbestos inspection

    ReplyDelete
  13. i never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. hazard perception test sa

    ReplyDelete
  14. -->create a trigger on Lead.
    --> When you convert leads to contacts or accounts, the process sometimes creates duplicate records.
    -->Use Contact field to query the related Lead and then merge them with the Contact.

    ReplyDelete
  15. Excellent and very cool idea and the subject at the top of magnificence and I am happy to comment on this topic through which we address the idea of positive re like this.
    CRM Software in Denmark

    ReplyDelete
  16. This is very significant, and yet necessary towards just click this unique backlink: Viking, Sub-Zero, GE REFRIGERATOR REPAIR IN HIGHLAND

    ReplyDelete
  17. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.thanks a lot guys.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete

  18. 360DigiTMG, Indore is a leading solutions provider of Training and Consulting to assist students, professionals by delivering top-notch, world-class classroom and online training. It offers courses in ai training in indore.









    ReplyDelete
  19. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  20. Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple Linear Regression
    data science interview questions
    KNN Algorithm

    ReplyDelete
  21. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  22. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    data science interview questions

    ReplyDelete

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...