-1
public class APShippingChargesApplytoDealController{
   public AcctSeed__Account_Payable__c Ap {get;set;}
   public List<Deal__c> dlList {get;set;}
   public String apId {get;set;}
   public String SearchItem {get;set;}

public APShippingChargesApplytoDealController(){
    apId = Apexpages.currentPage().getParameters().get('id');
    Ap = new AcctSeed__Account_Payable__c();
    Ap = [Select id, Name, AcctSeed__Vendor__r.Name, Freight_Applied__c, AcctSeed__Net_Amount__c, Enter_the_Deal_Invoice_Number__c, AcctSeed__Date__c from AcctSeed__Account_Payable__c where id =: apId];
}

  public pagereference displaySearch(){
    dlList = new List<Deal__c>();
    dlList = [select id, Name, Estimated_Ship_Week__c, Shipping_Account_Payable__c, Office_Shipping_Quote__c, Invoice_Number__c, Account__r.Owner.Name from Deal__c where  Invoice_Number__c like : '%' + SearchItem + '%' limit 1 ];
    return null;         
}

  public pagereference reset(){
      SearchItem = '';
      dlList.Clear();
      return null;
  }

  public void dealToAP(){
      dlList.get(0).Shipping_Account_Payable__c = Ap.Name;
      dlList.get(0).Actual_Shipping__c = Ap.AcctSeed__Net_Amount__c;
      dlList.get(0).Shipping_Company__c = Ap.AcctSeed__Vendor__r.Name;
      dlList.get(0).Actual_Shipping_Invoice_Date__c = Ap.AcctSeed__Date__c;
      update dlList;
      Ap.Freight_Applied__c = true;
      update Ap;
  }

}

Test class

 @isTest
   private class TestAPShippingChargesApplytoDeal{

static testMethod void myUnitTest(){

    Account acc = new Account();
    acc.Name = 'Execute Account';
    insert acc;

    AcctSeed__Accounting_Period__c accPeriod = new AcctSeed__Accounting_Period__c();
    accPeriod.Name = '2015-12';
    accPeriod.AcctSeed__Start_Date__c = date.Today();
    accPeriod.AcctSeed__End_Date__c = date.Today()+3;
    accPeriod.AcctSeed__Status__c = 'Open';
    insert accPeriod;

    Contact c = new contact();
    c.FirstName = 'Nihar';
    c.LastName = 'Sharma';
    insert c;

    AcctSeed__Account_Payable__c ap = new AcctSeed__Account_Payable__c();
    ap.AcctSeed__Status__c = 'In Process';
    ap.AcctSeed__Date__c = system.today();
    ap.AcctSeed__Payee_Reference__c = 'Nihar Cloud';
    ap.AcctSeed__Vendor__c = acc.id;
    ap.AcctSeed__Accounting_Period__c = accPeriod.id;
    insert ap;

    Deal__c dl = new Deal__c();
    dl.Account__c = acc.Id;
    dl.Name = 'Deal 123';
    dl.Close_Date__c = system.today()+4;
    insert dl;

    Apexpages.currentPage().getParameters().put('Id', ap.Id);

    APShippingChargesApplytoDealController controller = new APShippingChargesApplytoDealController();
    controller.displaySearch();
    controller.reset();


    dl.Shipping_Account_Payable__c = ap.Id;
    dl.Actual_Shipping__c = 100;
    dl.Shipping_Company__c = 'Nihar Cloud';
    dl.Actual_Shipping_Invoice_Date__c = date.Today();
    update dl;
    controller.displaySearch();


}    

}

  • In which line you are getting this error. – Tushar Sharma Aug 10 '15 at 13:08
  • controller.displaySearch(); this line show error in test class – Ravi Vadher Aug 10 '15 at 13:12
  • 1
    dlList.get(0).Shipping_Account_Payable__c = Ap.Name; this line error show in apex class so please help us – Ravi Vadher Aug 10 '15 at 13:20
  • I already give you answer. Please check in dlList you are getting any record . try to debug this. – Tushar Sharma Aug 10 '15 at 13:28
3

If this line

dlList = [select id, Name, Estimated_Ship_Week__c, Shipping_Account_Payable__c, Office_Shipping_Quote__c, Invoice_Number__c, Account__r.Owner.Name from Deal__c where Invoice_Number__c like : '%' + SearchItem + '%' limit 1 ];

don't have any record then it will give you this error. try to create Deal__c record with match the condition Invoice_Number__c like : '%' + SearchItem + '%' Pass value in SearchItem and same in Invoice_Number__c. it will solve your problem.. try to print(use debug) SearchItem value and then compare.

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.