-3

Class:

public class CreatePurchaseorder{

    public Purchase_order_setting__c pos {get;set;}

    public boolean isInput{get;set;}

    public id poid{get;set;}

    public boolean isUpdt{get;set;}

    public boolean isSave{get;set;}

    public boolean isdeleter{get;set;}

    public boolean iscancel{get;set;}

    public CreatePurchaseorder(){

        pos = new Purchase_order_setting__c ();
        isInput = true;
        isSave = true;
        iscancel=true;
        isUpdt = false;
        Id poid= ApexPages.currentPage().getParameters().get('poid');

      String nm = ApexPages.currentPage().getParameters().get('str');

        pos .Name= NM;


    }

    public void saveCon(){

        insert pos ;
        isInput = false;
        isSave = false;
        //isUpdt = false;
    }
     public void Cancel(){
      insert pos ;
        isInput = false;
        isSave = false;
         iscancel=false;
        }


    public void editCon(){
        isInput = true;
        isSave = false;
        isUpdt = true;
    }

    public void updateCon(){
        isSave = false;
        update pos ;
        isUpdt = false;
        isInput = false;
    }

}

Test class :

@isTest
    public class CreatePurchaseorderTest{

        static testmethod void CreatePurchaseorderTestMethod(){   

        Purchase_order_setting__c objPurchaseOrder = new Purchase_order_setting__c();

        objPurchaseOrder.name= 'musqot';

        objPurchaseOrder.PO_Startnumber__c= 1;

        System.assertEquals('musqot', objPurchaseOrder.name);

        insert objPurchaseOrder;

        ApexPages.currentPage().getParameters().put('id', objPurchaseOrder.id);

        ApexPages.StandardController sc = new ApexPages.standardController(objPurchaseOrder);

        test.startTest();

        CreatePurchaseorder objcrePurchase = new CreatePurchaseorder();

        objcrePurchase.saveCon();

        objcrePurchase.Cancel();

        objcrePurchase.editCon();

        objcrePurchase.updateCon();
             }
        }

I'm getting this error:

Error Message System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [PO_Startnumber__c]: [PO_Startnumber__c]

Stack Trace Class.CreatePurchaseorder.saveCon: line 25, column 1

Class.CreatePurchaseorderTest.CreatePurchaseorderTestMethod: line 15, column 1

  • I reckon the PO_Startnumber__c field is missing. – Phil Hawthorn Jul 25 '14 at 11:25
  • i already assign that field in my test class.. – fsales572 Jul 25 '14 at 11:55
  • yeah but in the wrong place, i think you're not understanding whats happening in your code, the error is pretty clear it tells you that a required field is missing in saveCon – Phil Hawthorn Jul 25 '14 at 12:12
2

I think you mistakenly think that by setting the PO_Startnumber__c as follows:

objPurchaseOrder.PO_Startnumber__c= 1;

Prior to creating a CreatePurchaseorder instance:

    CreatePurchaseorder objcrePurchase = new CreatePurchaseorder();

    objcrePurchase.saveCon();

That you are somehow setting the PO_Startnumber__c within CreatePurchaserorder.

I think you need to set the PO_Startnumber__c on the objcrePurchase instance:

    CreatePurchaseorder objcrePurchase = new CreatePurchaseorder();
    objcrePurchase.pos.PO_Startnumber__c = 1;
    objcrePurchase.saveCon();

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.