+ Start a Discussion
Chaim Rosenfeld 8Chaim Rosenfeld 8 

test class giving System.TypeException: Invalid id value for this SObject type: a091g0000085HO8AAM error

hello , i am not being able to run my test class for this controller , 

public class addLaborProposalCntrl {
    Public string leadID{get;set;}
    Public string testlpropID{get;set;}
    Public Lead lead {get;set;}
    Public Laborer_Mid_Construction_Proposal__c lprop {get;set;}
    Public Laborer_Mid_Construction_Proposal__c testlprop {get;set;}

    
    public addLaborProposalCntrl () {                  
    testlprop = [SELECT Marketing_Material__c, Holiday_Coverage__c,Management_and_Supervision__c, Over_Time_Hours__c, Pricing__c , Payment_Terms__c,Statement_of_Work__c,Supplies_and_Equipment__c FROM Laborer_Mid_Construction_Proposal__c where Name LIKE 'Test%' Limit 1 ];
    leadID = apexpages.currentpage().getparameters().get('id');
    lead = new Lead(ID = leadID);
    lprop = new Laborer_Mid_Construction_Proposal__c(Lead__c = LeadID );
    
    }
Public PageReference saveRecordlprop(){
upsert lead;
update testlprop ; 
lprop.Marketing_Material__c = testlprop.Marketing_Material__c;
lprop.Holiday_Coverage__c = testlprop.Holiday_Coverage__c;
lprop.Management_and_Supervision__c = testlprop.Management_and_Supervision__c ;
lprop.Over_Time_Hours__c = testlprop.Over_Time_Hours__c ;
lprop.Payment_Terms__c = testlprop.Payment_Terms__c ;
lprop.Pricing__c = testlprop.Pricing__c ;
lprop.Statement_of_Work__c = testlprop.Statement_of_Work__c  ;
lprop.Supplies_and_Equipment__c = testlprop.Supplies_and_Equipment__c ;
upsert lprop;  
    PageReference p = new PageReference('/' + this.lprop.Id );
    return p;
}


}

this is my Test Class 

@isTest 
public class addLaborProposalCntrlTest{

static testMethod void testMethod1() {

        Lead testRecord= new Lead();
        
        testRecord.LastName = 'test name ';
        testRecord.Company = 'test company';
        testRecord.Status = 'new';
        testRecord.Credit_Limit_Amount__c = 12344;
        insert testRecord;

        Laborer_Mid_Construction_Proposal__c testRecord2 = new Laborer_Mid_Construction_Proposal__c();
        testRecord2.Lead__C = testRecord.ID;
        testRecord2.Marketing_Material__c = 'test';
        testRecord2.Holiday_Coverage__c = 'test';
        testRecord2.Management_and_Supervision__c = 'test';
        testRecord2.Over_Time_Hours__c = 'test';
        testRecord2.Payment_Terms__c = 'test';
        testRecord2.Pricing__c = 'test';
        testRecord2.Statement_of_Work__c = 'test';
        testRecord2.Supplies_and_Equipment__c = 'test';
        
        
        testRecord2.Name = 'test';
        insert testRecord2;
        
        update testRecord2;
        


        Test.setCurrentPage(Page.addJob);
        System.currentPageReference().getParameters().put('id', testRecord2.Id);
        
        addLaborProposalCntrl addjobCntrlTestIns = new addLaborProposalCntrl();
        
        addjobCntrlTestIns.saveRecordlprop();
    }
 }

it gives this error 

System.TypeException: Invalid id value for this SObject type: a091g0000085HO8AAM error 

can anyone please help me in this 
 
Best Answer chosen by Chaim Rosenfeld 8
Rajesh3699Rajesh3699
Hi ,

Your visualforce page receives, Lead Id.

Where as your giving the Id of  Laborer_Mid_Construction_Proposal__c  record which is testRecord2.
System.currentPageReference().getParameters().put('id', testRecord2.Id);

Thank You,
Rajesh Adiga P.

All Answers

Rajesh3699Rajesh3699
Hi ,

Your visualforce page receives, Lead Id.

Where as your giving the Id of  Laborer_Mid_Construction_Proposal__c  record which is testRecord2.
System.currentPageReference().getParameters().put('id', testRecord2.Id);

Thank You,
Rajesh Adiga P.
This was selected as the best answer
Chaim Rosenfeld 8Chaim Rosenfeld 8
thans Rajesh . it worked