• siddharth-Pandit
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
What am I missing?? I can't get any coverage and I'm new to all this Lead stuff
public class OLGALead {
    Lead olgaLead = new Lead();
    RecordType rType = new RecordType();
    Opportunity psOpp = new Opportunity();
    
    public OLGALead(Id leadID) {
        olgaLead = [Select Id, Account__c, Machine__c, Component_Group_Description__c, Interval__c, 
                        SMCS_Comp_Description__c, SMCS_Comp_Quantity_Code__c, SMCS_Job_Description__c,
                        SMU_Unit_of_Measure__c, SMU_Utilization__c, SMU_Value__c, 
                        Target_Date__c, Target_SMU__c, Target_Labor_Hours__c, 
                        Total_Labor_Amount__c, Total_Labor_Hours__c, Total_Parts_Amount__c, Total_Amount__c
                        from Lead where Id = :leadID];
        rType = [Select Id, DeveloperName, SobjectType from RecordType where SobjectType='Opportunity' and DeveloperName = 'Product_Support_Record_Type'];
        
    }
    public String convertOLGALead() {

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

        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        lc.setAccountId(olgaLead.Account__c);
        olgaLead = [Select Id, Name, ConvertedOpportunityId from Lead where Id = :olgaLead.Id];

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        return String.valueOf(lcr.isSuccess());
//        System.Debug('OLGA Lead: ' + olgaLead.ConvertedOpportunityId);
//        psOpp = [Select Id, RecordTypeId from Opportunity where Id = :olgaLead.ConvertedOpportunityId];
//        psOpp.RecordTypeId = rType.Id;
//        update psOpp;
    }
}
 
@isTest
public class OLGALeadTEST {
    
    static testMethod void OLGALeadTEST(){ 
    test.startTest();

    //creates an account
    RecordType rtAcct = [SELECT Id from RecordType WHERE Name = 'Customer Accounts' and SobjectType = 'Account' limit 1];
    Account a1 = new Account(Name = 'Staci Test Account', RecordType = rtAcct);
    insert a1; 
    System.debug('Created and inserted account'); 
        
    //creates a Machine
    //Machine__c m1 = new Machine__c();
    //m1.Name = 'TestMach';
    //m1.Account__c = a1.Id;
    //m1.Serial_Number__c = 'serNum';
    //m1.Make__c = 'make';
    //insert m1;

    
    //System.debug('Created and inserted machine');
    Id lrt = [SELECT Id, Name FROM RecordType WHERE Name = 'OLGA Leads'].id;  
    
    //creates a Lead
    Lead ld1 = new Lead();
        ld1.RecordTypeId = lrt;
        ld1.Account__c = a1.Id; 
        //ld1.Machine__c = m1.Id; 
        ld1.Component_Group_Description__c = 'This is a Component Group Description'; 
        ld1.Interval__c = 1.00; 
        ld1.SMCS_Comp_Description__c = 'This is the SMCS Comp Description'; 
        ld1.SMCS_Comp_Quantity_Code__c = 2468.00; 
        ld1.SMCS_Job_Description__c = 'This is the SMCS Job Description';
        ld1.SMU_Unit_of_Measure__c = 'Hours'; 
        ld1.SMU_Utilization__c = 13.00; 
        ld1.SMU_Value__c = 100.00; 
        ld1.Target_Date__c = Date.Today()+1; 
        ld1.Target_SMU__c = 130.00; 
        ld1.Target_Labor_Hours__c = 12.07; 
        ld1.Total_Labor_Amount__c = 25.00; 
        ld1.Total_Labor_Hours__c = 11.5; 
        ld1.Total_Parts_Amount__c = 22.00; 
        ld1.Total_Amount__c = 500.00;
        ld1.LastName = 'Gilmore';
        ld1.Company = 'Gilmore Inc';
    insert ld1;
    
    System.debug('Created and inserted lead');
   
   
    Database.LeadConvert lc = new Database.LeadConvert();
    lc.setLeadId(ld1.id);

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    lc.setAccountId(ld1.Account__c);
    
    Database.LeadConvertResult lcr = Database.convertLead(lc);
        
     
        
   System.assert(lcr.isSuccess());
   test.stopTest();  
        
  }
   
   





}

 
  • February 26, 2017
  • Like
  • 0
I am trying to cover a method which uses formula field.
This is my test class code:

SObject1__C coltype = new SObject1__C();
coltype.name = 'Name-3312';
insert coltype;
System.debug('--->SObject1.Name = '+coltype.name); // Gives 'Name-3312';

SObject2__C colObj = new SObject2__C();
colObj.SObject1__C = coltype.Id;
insert colObj;  

SObject3__C newCollP = new SObject3__C();
newCollP.SObject2__C = colObj.Id,
insert newCollP;

SObject3__C has a fomula field named 'Col_Type__C' which is evaluated as follows:
"SObject2__r.SObject1__r.Name"
System.debug('--->newCollP.Col_Type__C = '+ newCollP.Col_Type__C); //returns a2Hg0000001tqQ2

This 'Col_Type__C' field's value is then used in a method in a helper class which i am trying to cover. As posted by many, I have tried to query the object SObject3__C and populate the field Col_Type__C in the test class as below. But it's not populatting the formula field's value as 'Name-3312'. 
newCollP = [SELECT Id,SObject2__r.SObject1__r.Name, Col_Type__C from SObject3__C where Id=:newCollP.id];

When I debug Col_Type__C value in helper class it returns some ID. I need the value of  as name of SObject1__C.

What is missing in my code? How can I get the formula field populated? 

Any help is appreciated!
What am I missing?? I can't get any coverage and I'm new to all this Lead stuff
public class OLGALead {
    Lead olgaLead = new Lead();
    RecordType rType = new RecordType();
    Opportunity psOpp = new Opportunity();
    
    public OLGALead(Id leadID) {
        olgaLead = [Select Id, Account__c, Machine__c, Component_Group_Description__c, Interval__c, 
                        SMCS_Comp_Description__c, SMCS_Comp_Quantity_Code__c, SMCS_Job_Description__c,
                        SMU_Unit_of_Measure__c, SMU_Utilization__c, SMU_Value__c, 
                        Target_Date__c, Target_SMU__c, Target_Labor_Hours__c, 
                        Total_Labor_Amount__c, Total_Labor_Hours__c, Total_Parts_Amount__c, Total_Amount__c
                        from Lead where Id = :leadID];
        rType = [Select Id, DeveloperName, SobjectType from RecordType where SobjectType='Opportunity' and DeveloperName = 'Product_Support_Record_Type'];
        
    }
    public String convertOLGALead() {

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

        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        lc.setAccountId(olgaLead.Account__c);
        olgaLead = [Select Id, Name, ConvertedOpportunityId from Lead where Id = :olgaLead.Id];

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        return String.valueOf(lcr.isSuccess());
//        System.Debug('OLGA Lead: ' + olgaLead.ConvertedOpportunityId);
//        psOpp = [Select Id, RecordTypeId from Opportunity where Id = :olgaLead.ConvertedOpportunityId];
//        psOpp.RecordTypeId = rType.Id;
//        update psOpp;
    }
}
 
@isTest
public class OLGALeadTEST {
    
    static testMethod void OLGALeadTEST(){ 
    test.startTest();

    //creates an account
    RecordType rtAcct = [SELECT Id from RecordType WHERE Name = 'Customer Accounts' and SobjectType = 'Account' limit 1];
    Account a1 = new Account(Name = 'Staci Test Account', RecordType = rtAcct);
    insert a1; 
    System.debug('Created and inserted account'); 
        
    //creates a Machine
    //Machine__c m1 = new Machine__c();
    //m1.Name = 'TestMach';
    //m1.Account__c = a1.Id;
    //m1.Serial_Number__c = 'serNum';
    //m1.Make__c = 'make';
    //insert m1;

    
    //System.debug('Created and inserted machine');
    Id lrt = [SELECT Id, Name FROM RecordType WHERE Name = 'OLGA Leads'].id;  
    
    //creates a Lead
    Lead ld1 = new Lead();
        ld1.RecordTypeId = lrt;
        ld1.Account__c = a1.Id; 
        //ld1.Machine__c = m1.Id; 
        ld1.Component_Group_Description__c = 'This is a Component Group Description'; 
        ld1.Interval__c = 1.00; 
        ld1.SMCS_Comp_Description__c = 'This is the SMCS Comp Description'; 
        ld1.SMCS_Comp_Quantity_Code__c = 2468.00; 
        ld1.SMCS_Job_Description__c = 'This is the SMCS Job Description';
        ld1.SMU_Unit_of_Measure__c = 'Hours'; 
        ld1.SMU_Utilization__c = 13.00; 
        ld1.SMU_Value__c = 100.00; 
        ld1.Target_Date__c = Date.Today()+1; 
        ld1.Target_SMU__c = 130.00; 
        ld1.Target_Labor_Hours__c = 12.07; 
        ld1.Total_Labor_Amount__c = 25.00; 
        ld1.Total_Labor_Hours__c = 11.5; 
        ld1.Total_Parts_Amount__c = 22.00; 
        ld1.Total_Amount__c = 500.00;
        ld1.LastName = 'Gilmore';
        ld1.Company = 'Gilmore Inc';
    insert ld1;
    
    System.debug('Created and inserted lead');
   
   
    Database.LeadConvert lc = new Database.LeadConvert();
    lc.setLeadId(ld1.id);

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    lc.setAccountId(ld1.Account__c);
    
    Database.LeadConvertResult lcr = Database.convertLead(lc);
        
     
        
   System.assert(lcr.isSuccess());
   test.stopTest();  
        
  }
   
   





}

 
  • February 26, 2017
  • Like
  • 0