• neeraj singh 20
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I have a trigger on lead convert that creates a record in a managed package app.  When I run my test code, i get the following error: "Methods defined as TestMethod do not support Web service callouts". I have tried the httpmock code and istestrunning.  What am I missing?

Here is my trigger
trigger LeadConvert on Lead (after Insert,after update) {
   String recordTypeName = 'ID Lead Record Type'; // <-- Change this to your record type name
  
  Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Lead.getRecordTypeInfosByName();
  Schema.RecordTypeInfo rtInfo =  rtMapByName.get(recordTypeName);
  id recordTypeId = rtInfo.getRecordTypeId();
 if(!test.isrunningtest()) {
 For(Lead o : Trigger.New){
 If(o.RecordTypeId == recordTypeId){
 
  // no bulk processing; will only run from the UI
  if (Trigger.new.size() == 1) {

    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {

      // if a new account was created
      if (Trigger.new[0].ConvertedAccountId != null) {

        // update the converted account with some text from the lead
        Account a = [Select a.Id, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
        a.Description = Trigger.new[0].Name;
        update a;

      }          

      // if a new contact was created
      if (Trigger.new[0].ConvertedContactId != null) {

        // update the converted contact with some text from the lead
        Contact c = [Select c.Id, c.Description, c.Name From Contact c Where c.Id = :Trigger.new[0].ConvertedContactId];
        c.Description = Trigger.new[0].Name;
        update c;
         
If(o.Create_Apttus_Proposal__c == True) {
        // insert a custom object associated with the contact
       
        Apttus_Proposal__Proposal__c obj = new Apttus_Proposal__Proposal__c();
        obj.Apttus_Proposal__Proposal_Name__c = c.Name;
        obj.Apttus_Proposal__Description__c = c.Description;
        obj.Apttus_Proposal__Account__c = Trigger.new[0].ConvertedAccountId;
        obj.Due_to_Funder__c = Date.today().addDays(+60);
        obj.Program__c = Trigger.new[0].Program__c;
        obj.Proposal_Reviewer_list__c = Trigger.new[0].Proposal_Reviewer_list__c;
        obj.Total_Proposal_Value__c = 1;
        obj.Apttus_Proposal__ExpectedStartDate__c = Date.today().addDays(+60);
        obj.Apttus_Proposal__ExpectedEndDate__c = Date.today().addDays(+365);
        obj.Account_Contact__c = Trigger.new[0].ConvertedContactId;
        obj.Lead_Id__c = c.id;
        obj.Proposal_Status__c = 'Awaiting RFP';
        insert obj;
}}{
      }

     

   } }

  }     

}
}
}
Here is my test code:
 
@isTest
public class LeadConvertTest {
   
    static testMethod void insertNewLead() {

        Lead newLead = new Lead();
        newLead.LastName = 'Lee';
        newLead.FirstName = 'James';
       newLead.Company = 'TestTrigger';
       newLead.Program__c = 'Assessment & Standards Development Services';
       newLead.Proposal_Reviewer_list__c = 'Aida Walqui';
       newLead.Create_Apttus_Proposal__c = True;

        insert newLead;
       
     test.startTest();
      Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
      

        Database.LeadConvert lc = new Database.LeadConvert();
       lc.setLeadId(newLead.id);

        
        

       LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
//lc.setConvertedStatus(convertStatus.MasterLabel);
lc.setConvertedStatus('Qualified');


       Database.LeadConvertResult lcr = Database.convertLead(lc);
        
        System.assert(lcr.isSuccess());

      test.stopTest();
    }

}


 
I have a trigger on lead convert that creates a record in a managed package app.  When I run my test code, i get the following error: "Methods defined as TestMethod do not support Web service callouts". I have tried the httpmock code and istestrunning.  What am I missing?

Here is my trigger
trigger LeadConvert on Lead (after Insert,after update) {
   String recordTypeName = 'ID Lead Record Type'; // <-- Change this to your record type name
  
  Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Lead.getRecordTypeInfosByName();
  Schema.RecordTypeInfo rtInfo =  rtMapByName.get(recordTypeName);
  id recordTypeId = rtInfo.getRecordTypeId();
 if(!test.isrunningtest()) {
 For(Lead o : Trigger.New){
 If(o.RecordTypeId == recordTypeId){
 
  // no bulk processing; will only run from the UI
  if (Trigger.new.size() == 1) {

    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {

      // if a new account was created
      if (Trigger.new[0].ConvertedAccountId != null) {

        // update the converted account with some text from the lead
        Account a = [Select a.Id, a.Description From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
        a.Description = Trigger.new[0].Name;
        update a;

      }          

      // if a new contact was created
      if (Trigger.new[0].ConvertedContactId != null) {

        // update the converted contact with some text from the lead
        Contact c = [Select c.Id, c.Description, c.Name From Contact c Where c.Id = :Trigger.new[0].ConvertedContactId];
        c.Description = Trigger.new[0].Name;
        update c;
         
If(o.Create_Apttus_Proposal__c == True) {
        // insert a custom object associated with the contact
       
        Apttus_Proposal__Proposal__c obj = new Apttus_Proposal__Proposal__c();
        obj.Apttus_Proposal__Proposal_Name__c = c.Name;
        obj.Apttus_Proposal__Description__c = c.Description;
        obj.Apttus_Proposal__Account__c = Trigger.new[0].ConvertedAccountId;
        obj.Due_to_Funder__c = Date.today().addDays(+60);
        obj.Program__c = Trigger.new[0].Program__c;
        obj.Proposal_Reviewer_list__c = Trigger.new[0].Proposal_Reviewer_list__c;
        obj.Total_Proposal_Value__c = 1;
        obj.Apttus_Proposal__ExpectedStartDate__c = Date.today().addDays(+60);
        obj.Apttus_Proposal__ExpectedEndDate__c = Date.today().addDays(+365);
        obj.Account_Contact__c = Trigger.new[0].ConvertedContactId;
        obj.Lead_Id__c = c.id;
        obj.Proposal_Status__c = 'Awaiting RFP';
        insert obj;
}}{
      }

     

   } }

  }     

}
}
}
Here is my test code:
 
@isTest
public class LeadConvertTest {
   
    static testMethod void insertNewLead() {

        Lead newLead = new Lead();
        newLead.LastName = 'Lee';
        newLead.FirstName = 'James';
       newLead.Company = 'TestTrigger';
       newLead.Program__c = 'Assessment & Standards Development Services';
       newLead.Proposal_Reviewer_list__c = 'Aida Walqui';
       newLead.Create_Apttus_Proposal__c = True;

        insert newLead;
       
     test.startTest();
      Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
      

        Database.LeadConvert lc = new Database.LeadConvert();
       lc.setLeadId(newLead.id);

        
        

       LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
//lc.setConvertedStatus(convertStatus.MasterLabel);
lc.setConvertedStatus('Qualified');


       Database.LeadConvertResult lcr = Database.convertLead(lc);
        
        System.assert(lcr.isSuccess());

      test.stopTest();
    }

}