• mahe
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 9
    Replies
Hi, I was trying to write test case for below class and I was covered 40% only.
Can you please help me to cover for 75% .

public with sharing class Receive_Deliverables {
    string tempDels{get; set;}
    string[] deliArray;
    public string DSId{get;set;}
    public String confirmmsg{get;set;}
    public List<Deliverable__c> lstdels;
    boolean isUnreceive = false;
    public string PrevPageUrl = ApexPages.currentPage().getUrl();

public Receive_Deliverables() {      
        DSId= ApexPages.currentPage().getParameters().get('id');
        UnreceiveLines = getUnreceiveLines();
//refreshPage=false;

    }

public Receive_Deliverables(ApexPages.StandardSetController controller) {
        System.debug('Selected deliverables : '+ApexPages.currentPage().getParameters().get('DeliverablesIds'));
        if(ApexPages.currentPage().getParameters().get('DeliverablesIds') != null){
             tempDels= ApexPages.currentPage().getParameters().get('DeliverablesIds');
             deliArray = tempDels.split(',');
             DSId= ApexPages.currentPage().getParameters().get('id');
             UnreceiveLines = getUnreceiveLines();                                             
        }
      
    }


List<Deliverable__c> ConfirmedDels{get;set;}
    Map<Id, Deliverable__c> InvoiceAmount;
    List<Deliverable__c> UnreceiveLines{get;set;}
    public string getDSId(){
     return DSId= ApexPages.currentPage().getParameters().get('id');

    }

public List<Deliverable__c> getConfirmedDels() {
    if(ConfirmedDels == null)
       ConfirmedDels=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Invoice_Date__c,PO_Number__c from Deliverable__c where Id IN : deliArray and (Approval_Status__c =: 'Not Completed' Or Approval_Status__c =: 'Deliverable Completed')];
         System.debug('Confirmed Deliverables: '+ConfirmedDels.size());
              
       return ConfirmedDels ;
    }

public List<Deliverable__c> getUnreceiveLines(){
            if(UnreceiveLines == null )
             UnreceiveLines=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,PO_Number__c from Deliverable__c where Opportunity__c =:DSId and (Approval_Status__c =: 'Deliverable Approved for Payment') ];
     
                return UnreceiveLines;
        }

public Map<Id, Deliverable__c> getInvoiceAmount(){
            if(InvoiceAmount == null){
                InvoiceAmount = new Map<Id, Deliverable__c>();
                for(Deliverable__c del : getConfirmedDels()){              
                   InvoiceAmount.put(del.Id,del);              
                }
            }
            return InvoiceAmount ;
      
       }

public void ReceiveDeliverable(){
   
    try{
        if(ConfirmedDels.size() > 0 ){
        Boolean IsInvoiceAmountGreaterthanDeliAmount = false;
        if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = new List<deliverable__c>();
    }                   
        for(Deliverable__c deli : ConfirmedDels){
                deli.Approval_Status__c = 'Deliverable Completed';
                System.debug('Partial Amount: '+deli.Partial_Amount__c);
                if(deli.Partial_Amount__c == 0){
                        deli.Partial_Amount__c = null;
                }
                if(deli.Partial_Amount__c > deli.Deliverable_Amount__c){                   
                        IsInvoiceAmountGreaterthanDeliAmount = true;
                }
                if(deli.Partial_Amount__c <> null ){
              
                        if(deli.Make_Partial_Payment__c == false){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Please check [Make Partial Payment?]field when you trying to do partail receive'));
                        }
                }
        }
        List<Database.Saveresult> Dbresult;
        if(!IsInvoiceAmountGreaterthanDeliAmount){                     
           Dbresult = Database.update(ConfirmedDels);
        }
        else
        {             
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'You cannot receive deliverable morethan deliverable amount. Invoice Amount should be less than or equal to Deliverable amount.'));
        }
      
           for(Integer i =0;i< ConfirmedDels.size();i++){
         
                if(Dbresult[i].isSuccess()){
                        try{
                        // create the new approval request to submit
                        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                        req.setComments('Submitted for approval. Please approve.');
                        req.setObjectId(ConfirmedDels[i].Id);
                        // submit the approval request for processing
                        Approval.ProcessResult result = Approval.process(req);
                        // display if the reqeust was successful
                        System.debug('Submitted for approval successfully: '+result.isSuccess());                                              
                          UnreceiveLines.add(ConfirmedDels[i]); 
                        }
                        catch(Exception ex){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Unable to Submit the Record , please check the entry criteria.'));
                                 PageReference OppPage = Page.View_List_Of_Deliverables;
 
  

                        }
                }       
          
            }


if(Dbresult[0].isSuccess()){
confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));                       
            }
        }
    }
    catch(Exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = getUnreceiveLines();
    }
   
     
}

public void UnReceiveDeliverable(){
    
    try{     
            if(UnreceiveLines.size()>0){
                   
                for(Deliverable__c del : UnreceiveLines){
                        if(del.IsLocked ){
                                // create the new approval request to submit
                                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();               
                                req.setComments('Submitted for Unreceive deliverable/PO line.');
                                req.setObjectId(del.Id);
                                // submit the approval request for processing
                                Approval.ProcessResult result = Approval.process(req);
                                // display if the reqeust was successful
                                System.debug('Submitted for approval successfully: '+result.isSuccess());
                        }
               
               
                   
                        del.Approval_Status__c ='Not Completed';
                        del.Work_Approved_By__c= null;                    
                        del.Approved_By_Date__c=null;
                        del.Contractor_Invoice__c = null;
                        if(del.Make_Partial_Payment__c){
                                del.Make_Partial_Payment__c=false;
                                del.Partial_Amount__c=Decimal.valueOf('0');
                        }
                   
                }
               update UnreceiveLines;
             
               
            if(UnreceiveLines.size() == 1)
                ApexPages.addmessage(new ApexPages.message( ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverable got Unreceived successfully, Please close the window'));
               
            if(UnreceiveLines.size() >1)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverables got Unreceived successfully , Please close the window'));
           }
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }


}



public PageReference goBack() {
    string id = ApexPages.currentPage().getParameters().get('id');
    PageReference OppPage = Page.View_List_Of_Deliverables;//new PageReference('https://na3.salesforce.com/apex/View_List_Of_Deliverables?id=' + id );
    OppPage.getParameters().put('id', id);
    OppPage.setRedirect(true); 
      return OppPage;
   }



public PageReference RedirectToActualPage(){
       
    PageReference OppPage_actual = new PageReference(PrevPageUrl);
    OppPage_actual.setRedirect(true);
    return OppPage_actual;
}

public PageReference CancelAction(){
string id = ApexPages.currentPage().getParameters().get('id');
PageReference OppPage = new PageReference('/' + id );
OppPage.setRedirect(true);
return OppPage;
}

}
  • April 11, 2014
  • Like
  • 1
Hi Friends,

I am trying to complete 75% test case for below apex calss but I only coverd 36%. Can you please anyone help on this.

public with sharing class Receive_Deliverables {
    string tempDels{get; set;}
    string[] deliArray;
    public string DSId{get;set;}
    public String confirmmsg{get;set;}
    public List<Deliverable__c> lstdels;
    boolean isUnreceive = false;
    public string PrevPageUrl = ApexPages.currentPage().getUrl();
// public Boolean refreshPage {get; set;}


    public Receive_Deliverables() {       
        DSId= ApexPages.currentPage().getParameters().get('id');
        UnreceiveLines = getUnreceiveLines();
//refreshPage=false;

    }



    public Receive_Deliverables(ApexPages.StandardSetController controller) {
        System.debug('Selected deliverables : '+ApexPages.currentPage().getParameters().get('DeliverablesIds'));
        if(ApexPages.currentPage().getParameters().get('DeliverablesIds') != null){
             tempDels= ApexPages.currentPage().getParameters().get('DeliverablesIds');
             deliArray = tempDels.split(',');
             DSId= ApexPages.currentPage().getParameters().get('id');
             UnreceiveLines = getUnreceiveLines();                                              
        }
       
    }
      
    List<Deliverable__c> ConfirmedDels{get;set;}
    Map<Id, Deliverable__c> InvoiceAmount;
    List<Deliverable__c> UnreceiveLines{get;set;}
    public string getDSId(){
     return DSId= ApexPages.currentPage().getParameters().get('id');

    }
    
    public List<Deliverable__c> getConfirmedDels() {
    if(ConfirmedDels == null)
       ConfirmedDels=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Invoice_Date__c,PO_Number__c from Deliverable__c where Id IN : deliArray and (Approval_Status__c =: 'Not Completed' Or Approval_Status__c =: 'Deliverable Completed')];
         System.debug('Confirmed Deliverables: '+ConfirmedDels.size());
               
       return ConfirmedDels ;
    }

        public List<Deliverable__c> getUnreceiveLines(){
            if(UnreceiveLines == null )
             UnreceiveLines=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,PO_Number__c from Deliverable__c where Opportunity__c =:DSId and (Approval_Status__c =: 'Deliverable Approved for Payment') ];
      
                return UnreceiveLines;
        }
      
       
       public Map<Id, Deliverable__c> getInvoiceAmount(){
            if(InvoiceAmount == null){
                InvoiceAmount = new Map<Id, Deliverable__c>();
                for(Deliverable__c del : getConfirmedDels()){               
                   InvoiceAmount.put(del.Id,del);               
                }
            }
            return InvoiceAmount ;
       
       }
      

      
      
public void ReceiveDeliverable(){
    
    try{
        if(ConfirmedDels.size() > 0 ){
        Boolean IsInvoiceAmountGreaterthanDeliAmount = false;
        if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = new List<deliverable__c>();
    }                    
        for(Deliverable__c deli : ConfirmedDels){
                deli.Approval_Status__c = 'Deliverable Completed';
                System.debug('Partial Amount: '+deli.Partial_Amount__c);
                if(deli.Partial_Amount__c == 0){
                        deli.Partial_Amount__c = null;
                }
                if(deli.Partial_Amount__c > deli.Deliverable_Amount__c){                    
                        IsInvoiceAmountGreaterthanDeliAmount = true;
                }
                if(deli.Partial_Amount__c <> null ){
               
                        if(deli.Make_Partial_Payment__c == false){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Please check [Make Partial Payment?]field when you trying to do partail receive'));
                        }
                }
        }
        List<Database.Saveresult> Dbresult;
        if(!IsInvoiceAmountGreaterthanDeliAmount){                      
           Dbresult = Database.update(ConfirmedDels);
        }
        else
        {              
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'You cannot receive deliverable morethan deliverable amount. Invoice Amount should be less than or equal to Deliverable amount.'));
        }
       
           for(Integer i =0;i< ConfirmedDels.size();i++){
          
                if(Dbresult[i].isSuccess()){
                        try{
                        // create the new approval request to submit
                        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                        req.setComments('Submitted for approval. Please approve.');
                        req.setObjectId(ConfirmedDels[i].Id);
                        // submit the approval request for processing
                        Approval.ProcessResult result = Approval.process(req);
                        // display if the reqeust was successful
                        System.debug('Submitted for approval successfully: '+result.isSuccess());                                               
                          UnreceiveLines.add(ConfirmedDels[i]);  
                        }
                        catch(Exception ex){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Unable to Submit the Record , please check the entry criteria.'));
                                 PageReference OppPage = Page.View_List_Of_Deliverables;
  
   

                        }
                }        
           
            }
           
                        //List<Deliverable__c> lstdels =getUnreceiveLines();
           if(Dbresult[0].isSuccess()){
               
                            
                   // if(ConfirmedDels.size() >1)
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully Received in Salesforce. Please click “Close” button to close this window or click “Back to Step 1” button if you want to receive another deliverable.'));
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.  REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers).\n 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
      //confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';
      //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
                                           // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,ConfirmedDels.size() +' Deliverables got received successfully , Please close the window'));
               
              //  if(ConfirmedDels.size() == 1)
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully Received in Salesforce. Please click “Close” button to close this window or click “Back to Step 1” button if you want to receive another deliverable.'));
                       // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.  REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). \n 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
      confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';
      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));                       
            }
        }
    }
    catch(Exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = getUnreceiveLines();
    }
   
     
}

public void UnReceiveDeliverable(){
    
    try{     
            if(UnreceiveLines.size()>0){
                   
                for(Deliverable__c del : UnreceiveLines){
                        if(del.IsLocked ){
                                // create the new approval request to submit
                                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();               
                                req.setComments('Submitted for Unreceive deliverable/PO line.');
                                req.setObjectId(del.Id);
                                // submit the approval request for processing
                                Approval.ProcessResult result = Approval.process(req);
                                // display if the reqeust was successful
                                System.debug('Submitted for approval successfully: '+result.isSuccess());
                        }
               
               
                   
                        del.Approval_Status__c ='Not Completed';
                        del.Work_Approved_By__c= null;                    
                        del.Approved_By_Date__c=null;
                        del.Contractor_Invoice__c = null;
                        if(del.Make_Partial_Payment__c){
                                del.Make_Partial_Payment__c=false;
                                del.Partial_Amount__c=Decimal.valueOf('0');
                        }
                   
                }
               update UnreceiveLines;
             
               
            if(UnreceiveLines.size() == 1)
                ApexPages.addmessage(new ApexPages.message( ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverable got Unreceived successfully, Please close the window'));
               
            if(UnreceiveLines.size() >1)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverables got Unreceived successfully , Please close the window'));
           }
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   //PageReference OppPage = Page.View_List_Of_Deliverables;
  
   // OppPage.getParameters().put('id', ApexPages.currentPage().getParameters().get('id'));
    //OppPage.setRedirect(true); 
    //  return OppPage;
}



public PageReference goBack() {
    string id = ApexPages.currentPage().getParameters().get('id');
    PageReference OppPage = Page.View_List_Of_Deliverables;//new PageReference('https://na3.salesforce.com/apex/View_List_Of_Deliverables?id=' + id );
    OppPage.getParameters().put('id', id);
    OppPage.setRedirect(true); 
      return OppPage;
   }



public PageReference RedirectToActualPage(){
       
    PageReference OppPage_actual = new PageReference(PrevPageUrl);
    OppPage_actual.setRedirect(true);
    return OppPage_actual;
}

public PageReference CancelAction(){
string id = ApexPages.currentPage().getParameters().get('id');
PageReference OppPage = new PageReference('/' + id );
OppPage.setRedirect(true);
return OppPage;
}

}
  • April 10, 2014
  • Like
  • 1
public with sharing class Receive_Deliverables {
    string tempDels{get; set;}
    string[] deliArray;
    public string DSId{get;set;}
    public String confirmmsg{get;set;}
    public List<Deliverable__c> lstdels;
    boolean isUnreceive = false;
    public string PrevPageUrl = ApexPages.currentPage().getUrl();
// public Boolean refreshPage {get; set;}


    public Receive_Deliverables() {       
        DSId= ApexPages.currentPage().getParameters().get('id');
        UnreceiveLines = getUnreceiveLines();
//refreshPage=false;

    }



    public Receive_Deliverables(ApexPages.StandardSetController controller) {
        System.debug('Selected deliverables : '+ApexPages.currentPage().getParameters().get('DeliverablesIds'));
        if(ApexPages.currentPage().getParameters().get('DeliverablesIds') != null){
             tempDels= ApexPages.currentPage().getParameters().get('DeliverablesIds');
             deliArray = tempDels.split(',');
             DSId= ApexPages.currentPage().getParameters().get('id');
             UnreceiveLines = getUnreceiveLines();                                              
        }
       
    }
      
    List<Deliverable__c> ConfirmedDels{get;set;}
    Map<Id, Deliverable__c> InvoiceAmount;
    List<Deliverable__c> UnreceiveLines{get;set;}
    public string getDSId(){
     return DSId= ApexPages.currentPage().getParameters().get('id');

    }
    
    public List<Deliverable__c> getConfirmedDels() {
    if(ConfirmedDels == null)
       ConfirmedDels=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Invoice_Date__c,PO_Number__c from Deliverable__c where Id IN : deliArray and (Approval_Status__c =: 'Not Completed' Or Approval_Status__c =: 'Deliverable Completed')];
         System.debug('Confirmed Deliverables: '+ConfirmedDels.size());
               
       return ConfirmedDels ;
    }

        public List<Deliverable__c> getUnreceiveLines(){
            if(UnreceiveLines == null )
             UnreceiveLines=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,PO_Number__c from Deliverable__c where Opportunity__c =:DSId and (Approval_Status__c =: 'Deliverable Approved for Payment') ];
      
                return UnreceiveLines;
        }
      
       
       public Map<Id, Deliverable__c> getInvoiceAmount(){
            if(InvoiceAmount == null){
                InvoiceAmount = new Map<Id, Deliverable__c>();
                for(Deliverable__c del : getConfirmedDels()){               
                   InvoiceAmount.put(del.Id,del);               
                }
            }
            return InvoiceAmount ;
       
       }
      

      
      
public void ReceiveDeliverable(){
    
    try{
        if(ConfirmedDels.size() > 0 ){
        Boolean IsInvoiceAmountGreaterthanDeliAmount = false;
        if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = new List<deliverable__c>();
    }                    
        for(Deliverable__c deli : ConfirmedDels){
                deli.Approval_Status__c = 'Deliverable Completed';
                System.debug('Partial Amount: '+deli.Partial_Amount__c);
                if(deli.Partial_Amount__c == 0){
                        deli.Partial_Amount__c = null;
                }
                if(deli.Partial_Amount__c > deli.Deliverable_Amount__c){                    
                        IsInvoiceAmountGreaterthanDeliAmount = true;
                }
                if(deli.Partial_Amount__c <> null ){
               
                        if(deli.Make_Partial_Payment__c == false){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Please check [Make Partial Payment?]field when you trying to do partail receive'));
                        }
                }
        }
        List<Database.Saveresult> Dbresult;
        if(!IsInvoiceAmountGreaterthanDeliAmount){                      
           Dbresult = Database.update(ConfirmedDels);
        }
        else
        {              
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'You cannot receive deliverable morethan deliverable amount. Invoice Amount should be less than or equal to Deliverable amount.'));
        }
       
           for(Integer i =0;i< ConfirmedDels.size();i++){
          
                if(Dbresult[i].isSuccess()){
                        try{
                        // create the new approval request to submit
                        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                        req.setComments('Submitted for approval. Please approve.');
                        req.setObjectId(ConfirmedDels[i].Id);
                        // submit the approval request for processing
                        Approval.ProcessResult result = Approval.process(req);
                        // display if the reqeust was successful
                        System.debug('Submitted for approval successfully: '+result.isSuccess());                                               
                          UnreceiveLines.add(ConfirmedDels[i]);  
                        }
                        catch(Exception ex){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Unable to Submit the Record , please check the entry criteria.'));
                                 PageReference OppPage = Page.View_List_Of_Deliverables;
  
   

                        }
                }        
           
            }
           
                        //List<Deliverable__c> lstdels =getUnreceiveLines();
           if(Dbresult[0].isSuccess()){
               
                            
                   // if(ConfirmedDels.size() >1)
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully Received in Salesforce. Please click “Close” button to close this window or click “Back to Step 1” button if you want to receive another deliverable.'));
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.  REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers).\n 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
      //confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';
      //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
                                           // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,ConfirmedDels.size() +' Deliverables got received successfully , Please close the window'));
               
              //  if(ConfirmedDels.size() == 1)
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully Received in Salesforce. Please click “Close” button to close this window or click “Back to Step 1” button if you want to receive another deliverable.'));
                       // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.  REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). \n 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
      confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';
      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));                       
            }
        }
    }
    catch(Exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = getUnreceiveLines();
    }
   
     
}

public void UnReceiveDeliverable(){
    
    try{     
            if(UnreceiveLines.size()>0){
                   
                for(Deliverable__c del : UnreceiveLines){
                        if(del.IsLocked ){
                                // create the new approval request to submit
                                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();               
                                req.setComments('Submitted for Unreceive deliverable/PO line.');
                                req.setObjectId(del.Id);
                                // submit the approval request for processing
                                Approval.ProcessResult result = Approval.process(req);
                                // display if the reqeust was successful
                                System.debug('Submitted for approval successfully: '+result.isSuccess());
                        }
               
               
                   
                        del.Approval_Status__c ='Not Completed';
                        del.Work_Approved_By__c= null;                    
                        del.Approved_By_Date__c=null;
                        del.Contractor_Invoice__c = null;
                        if(del.Make_Partial_Payment__c){
                                del.Make_Partial_Payment__c=false;
                                del.Partial_Amount__c=Decimal.valueOf('0');
                        }
                   
                }
               update UnreceiveLines;
             
               
            if(UnreceiveLines.size() == 1)
                ApexPages.addmessage(new ApexPages.message( ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverable got Unreceived successfully, Please close the window'));
               
            if(UnreceiveLines.size() >1)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverables got Unreceived successfully , Please close the window'));
           }
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   //PageReference OppPage = Page.View_List_Of_Deliverables;
  
   // OppPage.getParameters().put('id', ApexPages.currentPage().getParameters().get('id'));
    //OppPage.setRedirect(true); 
    //  return OppPage;
}



public PageReference goBack() {
    string id = ApexPages.currentPage().getParameters().get('id');
    PageReference OppPage = Page.View_List_Of_Deliverables;//new PageReference('https://na3.salesforce.com/apex/View_List_Of_Deliverables?id=' + id );
    OppPage.getParameters().put('id', id);
    OppPage.setRedirect(true); 
      return OppPage;
   }



public PageReference RedirectToActualPage(){
       
    PageReference OppPage_actual = new PageReference(PrevPageUrl);
    OppPage_actual.setRedirect(true);
    return OppPage_actual;
}

public PageReference CancelAction(){
string id = ApexPages.currentPage().getParameters().get('id');
PageReference OppPage = new PageReference('/' + id );
OppPage.setRedirect(true);
return OppPage;
}

}
  • March 21, 2014
  • Like
  • 0

Hi , I was trying to fix below issue. can anyone help on this.

Save error: member variable not visible for assignment oppIds = ApexPages.currentPage().getParameters().get( 'id');

 

publicString oppIds

{

get

{

if ( oppIds == null)

{

oppIds = ApexPages.currentPage().getParameters().get( 'id');

}

returnoppIds;

}

 

}

  • December 16, 2013
  • Like
  • 0

Hi, I was trying to write test case for below class and I was covered 40% only.

Can you please help me to cover for 75% . thanks.

 

public

withsharingclassConfirm_UnreceiveDeliverables {

 

List<

Deliverable__c> Confirm_unReceiveDels{get; set;}

string[] deliverableArray;

string tempDels{

get; set;}

 

public string oppId='';

 

publicConfirm_UnreceiveDeliverables() {

oppId= ApexPages.currentPage().getParameters().

get('id');

tempDels= ApexPages.currentPage().getParameters().

get('DeliverablesIds');

 

if(tempDels <> null){

deliverableArray = tempDels.split(

',');

getConfirm_unReceiveDels();

}

}

publicConfirm_UnreceiveDeliverables(ApexPages.StandardSetController controller) {

oppId= ApexPages.currentPage().getParameters().

get('id');

tempDels= ApexPages.currentPage().getParameters().

get('DeliverablesIds');

 

if(tempDels <> null){

deliverableArray = tempDels.split(

',');

getConfirm_unReceiveDels();

}

}

public List<Deliverable__c> getConfirm_unReceiveDels() {

 

if(Confirm_unReceiveDels == null) Confirm_unReceiveDels = [select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c fromDeliverable__cwhere Id IN:deliverableArray ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment')returnConfirm_unReceiveDels ;

}

publicvoidUnReceiveDeliverable(){

 

try{ List<Deliverable__c> unReceivedDels = new List<Deliverable__c>();

Integer[] k =

newInteger[]{};

Integer j = 0;

if(Confirm_unReceiveDels.size()>0){

 

for(Deliverable__cdel : Confirm_unReceiveDels){

del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c =

true;

 

if(del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c){

 

// create the new approval request to submitApproval.ProcessSubmitRequest req = newApproval.ProcessSubmitRequest();

req.setComments(

'Submitted for Unreceive deliverable/PO line.');

req.setObjectId(del.Id);

// submit the approval request for processingApproval.ProcessResult result = Approval.process(req);

 

// display if the reqeust was successful

System.debug(

'Submitted for approval successfully: '+result.isSuccess());

}

if(del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c){

k.add(j);

del.Approval_Status__c =

'Not Completed';

del.Work_Approved_By__c=

null;

del.Approved_By_Date__c=

null;

del.Contractor_Invoice__c =

null;

del.Invoice_Date__c =

null;

 

if(del.Make_Partial_Payment__c){

del.Make_Partial_Payment__c=

false;

del.Partial_Amount__c=Decimal.valueOf(

'0');

}

del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c =

false;

unReceivedDels.Add(del);

}

j++;

}

updateunReceivedDels;

 

//for(Integer i : k){//if(unReceiveDels[i].Notify_DS_Owner_for_PO_TroubleShoot_Del__c){//unReceiveDels.remove(i);//} //}if(unReceivedDels.size() >1)

ApexPages.addmessage(

new ApexPages.message(ApexPages.severity.confirm,'You have successfully UnReceived in Salesforce. Please click “Close” button to close this window or click “UnReceive another deliverable” button if you want to unreceive another deliverable.'));

 

if(unReceivedDels.size() == 1)

ApexPages.addmessage(

new ApexPages.message(ApexPages.severity.confirm,'You have successfully UnReceived in Salesforce. Please click “Close” button to close this window or click “UnReceive another deliverable” button if you want to unreceive another deliverable.'));

 

}

}

catch(Exception e){

ApexPages.addmessage(

new ApexPages.message(ApexPages.severity.ERROR ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));

}

 

}

public

PageReference goBack()

{

string id = ApexPages.currentPage().getParameters().

get('id');

PageReference OppPage = Page.Un_Receive_Deliverables;

////PageReference('https://cs3.salesforce.com/apex/Un_Receive_Deliverables?&id=' + oppId);

OppPage.getParameters().put(

'id', id);

OppPage.setRedirect(

true);

 

returnOppPage;

 

}

publicPageReference CancelAction(){

string id = ApexPages.currentPage().getParameters().

get('id');

PageReference OppPage =

new PageReference('https://na3.salesforce.com/'+ oppId);

OppPage.setRedirect(

true);

 

returnOppPage;

}

 

 

}

 

 

  • December 13, 2013
  • Like
  • 0

Hi,

 

when I click the 'Estimate your organization's code coverage'.

 

I got the below message  .

Code Coverage: 77%

Your overall code coverage is currently 77%. To deploy code to production, you must have at least 75%.

 

 

But I am not able to deploy code in production.  could you please help me anyone on this.

 

thanks,

Mahendiran

 

  • October 27, 2013
  • Like
  • 0

Hi

 

Can you please help me to write teset case for below class. Thanks

 

public

withsharingclassListOf_Deliverables {

 

public string oppId='';

 

publicListOf_Deliverables(ApexPages.StandardSetController controller) {

oppId= ApexPages.currentPage().getParameters().

get('id');

 

//getDels();

 

}

publicListOf_Deliverables() {

oppId= ApexPages.currentPage().getParameters().

get('id');

getDels();

 

}

publicvoidsetOppId(string DSId){

oppId = DSId;

}

string UrltoOpen {

get;set;}

List<

Deliverable__c> dels{get; set;}

List<

Deliverable__c> unReceiveDels{get; set;}

 

publicstring getUrltoOpen(){

 

if(UrltoOpen == null || UrltoOpen == ''){

UrltoOpen =

'httpss://cs13.salesforce.com/apex/Receive_Deliverables?scontrolCaching=1&id=' + ApexPages.currentPage().getParameters().get('id') + '&DeliverablesIds=';

}

returnUrltoOpen;

}

public List<Deliverable__c> getDels() {

 

if(dels == null) dels = [select id,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c fromDeliverable__cwhere ((Approval_Status__c =: 'Not Completed') and Extracted__c =: true) and Update__c =: 'U'and PO_Number__c <> nulland Opportunity__c =:oppId ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment')returndels ;

}

public List<Deliverable__c> getUnReceiveDels() {

 

if(unReceiveDels == null) unReceiveDels = [select id,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c fromDeliverable__cwhere (Approval_Status__c =: 'Deliverable Approved for Payment'and (Extracted__c =: trueOR Make_Partial_Payment__c =: true )) and Update__c =: 'U'and PO_Number__c <> nulland Opportunity__c =:oppId ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment')returnunReceiveDels ;

}

publicPageReference ConfirmAction(){

 

string Del_Id=

null;

 

if(dels != null){

 

for(integer count=0; count< dels.size();count++)

{

if(dels[count].Notify_DS_Owner_for_PO_TroubleShoot_Del__c == true)

{

if(Del_Id != null){

Del_Id = Del_Id + dels[

count].Id +',';

}

else{

Del_Id = dels[

count].Id +',';

}

}

 

}

}

if(unReceiveDels != null){

 

for(integer count=0; count< unReceiveDels.size();count++)

{

if(unReceiveDels[count].Notify_DS_Owner_for_PO_TroubleShoot_Del__c == true)

{

if(Del_Id != null){

Del_Id = Del_Id + unReceiveDels[

count].Id +',';

}

else{

Del_Id = unReceiveDels[

count].Id +',';

}

}

 

}

}

string id = ApexPages.currentPage().getParameters().

get('id');

UrltoOpen = UrltoOpen+Del_Id;

PageReference OppPage =

new PageReference('/apex/Receive_Deliverables?scontrolCaching=1&id=' + id + '&DeliverablesIds='+Del_Id);

OppPage.setRedirect(

true);

 

returnOppPage;

}

publicPageReference CancelAction(){

string id = ApexPages.currentPage().getParameters().

get('id');

PageReference OppPage =

new PageReference('https://cs3.salesforce.com/'+ oppId);

OppPage.setRedirect(

true);

 

returnOppPage;

}

}

  • September 21, 2012
  • Like
  • 0

Hi I am trying to write test case for below class file. CAn any one help me ?

 Thanks.

 

public with sharing class ListOf_Deliverables { public string oppId=''; public ListOf_Deliverables(ApexPages.StandardSetController controller) { oppId= ApexPages.currentPage().getParameters().get('id'); //getDels(); } public ListOf_Deliverables() { oppId= ApexPages.currentPage().getParameters().get('id'); getDels(); } public void setOppId(string DSId){ oppId = DSId; } string UrltoOpen {get;set;} List<Deliverable__c> dels{get; set;} List<Deliverable__c> unReceiveDels{get; set;} public string getUrltoOpen(){ if(UrltoOpen == null || UrltoOpen == ''){ UrltoOpen = 'httpss://cs13.salesforce.com/apex/Receive_Deliverables?scontrolCaching=1&id=' + ApexPages.currentPage().getParameters().get('id') + '&DeliverablesIds='; } return UrltoOpen; } public List<Deliverable__c> getDels() { if(dels == null) dels = [select id,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c from Deliverable__c where ((Approval_Status__c =: 'Not Completed') and Extracted__c =: true) and Update__c =: 'U' and PO_Number__c <> null and Opportunity__c =:oppId ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment') return dels ; } public List<Deliverable__c> getUnReceiveDels() { if(unReceiveDels == null) unReceiveDels = [select id,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c from Deliverable__c where (Approval_Status__c =: 'Deliverable Approved for Payment' and (Extracted__c =: true OR Make_Partial_Payment__c =: true )) and Update__c =: 'U' and PO_Number__c <> null and Opportunity__c =:oppId ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment') return unReceiveDels ; } public PageReference ConfirmAction(){ string Del_Id=null; if(dels != null){ for(integer count=0; count< dels.size();count++) { if(dels[count].Notify_DS_Owner_for_PO_TroubleShoot_Del__c == true) { if(Del_Id != null){ Del_Id = Del_Id + dels[count].Id +','; } else{ Del_Id = dels[count].Id +','; } } } } if(unReceiveDels != null){ for(integer count=0; count< unReceiveDels.size();count++) { if(unReceiveDels[count].Notify_DS_Owner_for_PO_TroubleShoot_Del__c == true) { if(Del_Id != null){ Del_Id = Del_Id + unReceiveDels[count].Id +','; } else{ Del_Id = unReceiveDels[count].Id +','; } } } } string id = ApexPages.currentPage().getParameters().get('id'); UrltoOpen = UrltoOpen+Del_Id; PageReference OppPage = new PageReference('/apex/Receive_Deliverables?scontrolCaching=1&id=' + id + '&DeliverablesIds='+Del_Id); OppPage.setRedirect(true); return OppPage; } public PageReference CancelAction(){ string id = ApexPages.currentPage().getParameters().get('id'); PageReference OppPage = new PageReference('https://cs3.salesforce.com/' + oppId); OppPage.setRedirect(true); return OppPage; }}

  • September 21, 2012
  • Like
  • 0

Hi,

 

I wanted to hide custom button in standard objects detail page. So I did by implementing s-control and I made JavaScript code changes for it. Actually I can hide the button when the page first time loading but I count hide it when the refresh same page and its getting error out as following: 'window.parent.document.getElementsByName(...).0.style' is null or not an object.

 

var e=window.parent.document.getElementsByName("unreceive_deliverable1");
alert(" The count of button " + e.length);
e[0].style.display="none";

 

- unreceive_deliverable1 - is the button name

- I am getting count value is 1 when the page first time loading but getting 0 if I refresh the same page.

 

I am not sure where it is missing.  Please let me know if you have any question?

 

I appreciate if you could help me on this.

 

Thanks,

Mahendiran.

 

  • August 30, 2012
  • Like
  • 0
Hi, How to write test case for below class? Adavance thanks, public with sharing class Search_AESignatory { public List results{get;set;} // search results public string searchString{get;set;} // search keyword public Search_AESignatory() { // get the current search string searchString = System.currentPageReference().getParameters().get(​'lksrch'); runSearch(); } // performs the keyword search public PageReference search() { runSearch(); return null; } // prepare the query and issue the search command private void runSearch() { // TODO prepare query string for complex serarches & prevent injections results = performSearch(searchString); } // run the search and return the records found. private List performSearch(string searchString) { String soql; List lstAgreements = [Select Id,echosign_dev1__Opportunity__c from echosign_dev1__SIGN_Agreement__c where Id =: System.currentPageReference().getParameters().get(​'AgreementId')]; Opportunity opp = [Select Legal_Entity__c,Amount from Opportunity where Id =: lstAgreements[0].echosign_dev1__Opportunity__c limit 1]; if(opp.Amount >= 50000) { soql = 'select id, name,Legal_Entity_ies_Signatory_Can_Sign_For__c,Si​gnature_Authority__c from AE_Signatories__c where Legal_Entity_ies_Signatory_Can_Sign_For__c LIKE \'%'+ opp.Legal_Entity__c + '%\' AND Signature_Authority__c =\'VP+ (above USD 50K)\''; if(searchString != '' && searchString != null) soql = soql + ' And (name LIKE \'%' + searchString +'%\' Or Legal_Entity_ies_Signatory_Can_Sign_For__c Like \'%' + searchString +'%\') '; System.debug(soql); } else { soql = 'select id, name,Legal_Entity_ies_Signatory_Can_Sign_For__c,Si​gnature_Authority__c from AE_Signatories__c where Legal_Entity_ies_Signatory_Can_Sign_For__c LIKE \'%'+ opp.Legal_Entity__c + '%\' '; if(searchString != '' && searchString != null) soql = soql + ' And (name LIKE \'%' + searchString +'%\' Or Legal_Entity_ies_Signatory_Can_Sign_For__c Like \'%' + searchString +'%\') '; System.debug(soql); } soql = soql + 'Order by name ASC'; return database.query(soql); } // used by the visualforce page to send the link to the right dom element public string getFormTag() { return System.currentPageReference().getParameters().get(​'frm'); } // used by the visualforce page to send the link to the right dom element for the text box public string getTextBox() { return System.currentPageReference().getParameters().get(​'txt'); } } ..
  • July 18, 2012
  • Like
  • 0

Hi, How to write test case for below class?

Adavance thanks,

 

public with sharing class Search_AESignatory

{

public List results{get;set;} // search results

 public string searchString{get;set;} // search keyword

 

public Search_AESignatory()

{

// get the current search

string searchString = System.currentPageReference().getParameters().get('lksrch');

 runSearch();

}

// performs the keyword search

 

public PageReference search()

{ runSearch();

return null; } // prepare the query and issue the search command

 

private void runSearch()

 {

// TODO prepare query string for complex serarches & prevent injections

 results = performSearch(searchString);

 }

 // run the search and return the records found.

 

private List performSearch(string searchString)

{

 

String soql;

 

 List lstAgreements = [Select Id,echosign_dev1__Opportunity__c from echosign_dev1__SIGN_Agreement__c where Id =: System.currentPageReference().getParameters().get('AgreementId')];

 

Opportunity opp = [Select Legal_Entity__c,Amount from Opportunity where Id =: lstAgreements[0].echosign_dev1__Opportunity__c limit 1];

 

if(opp.Amount >= 50000)

 

{

 

soql = 'select id, name,Legal_Entity_ies_Signatory_Can_Sign_For__c,Signature_Authority__c from AE_Signatories__c where Legal_Entity_ies_Signatory_Can_Sign_For__c LIKE \'%'+ opp.Legal_Entity__c + '%\' AND Signature_Authority__c =\'VP+ (above USD 50K)\''; if(searchString != '' && searchString != null) soql = soql + ' And (name LIKE \'%' + searchString +'%\' Or Legal_Entity_ies_Signatory_Can_Sign_For__c Like \'%' + searchString +'%\') ';

 

System.debug(soql);

}

 

else

 

 {

 

soql = 'select id, name,Legal_Entity_ies_Signatory_Can_Sign_For__c,Signature_Authority__c from AE_Signatories__c where Legal_Entity_ies_Signatory_Can_Sign_For__c LIKE \'%'+ opp.Legal_Entity__c + '%\' '; if(searchString != '' && searchString != null) soql = soql + ' And (name LIKE \'%' + searchString +'%\' Or Legal_Entity_ies_Signatory_Can_Sign_For__c Like \'%' + searchString +'%\') ';

 

System.debug(soql);

 

 }

 

 soql = soql + 'Order by name ASC';

 

return database.query(soql);

 

}

 

// used by the visualforce page to send the link to the right dom element

 

public string getFormTag()

 {

return System.currentPageReference().getParameters().get('frm');

 }

// used by the visualforce page to send the link to the right dom element for the text box

 

public string getTextBox()

{

return System.currentPageReference().getParameters().get('txt');

 }

 

}

  • July 18, 2012
  • Like
  • 0

System.DmlException: Update failed. First exception on row 0 with id 0065000000JfoKmAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoReceiveDeliverable: execution of BeforeUpdate

 

caused by: System.DmlException: Process failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectDeliverableTrigger: execution of BeforeUpdate

 

caused by: System.Exception: Too many SOQL queries: 101

 

Class.DeliverableProject.ProjectApprovers: line 52, column 1

Trigger.ProjectDeliverableTrigger: line 35, column 1: []

 

Trigger.AutoReceiveDeliverable: line 59, column 1

 

Class.SyncPONumberOnDealSheet.updateDealSheetPONumber_list: line 38, column 1

  • June 15, 2012
  • Like
  • 0
I am getting following error: Update failed. First exception on row 0 with id 0065000000JfoKmAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoReceiveDeliverable: execution of BeforeUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error
  • June 15, 2012
  • Like
  • 0
Hi, I was trying to write test case for below class and I was covered 40% only.
Can you please help me to cover for 75% .

public with sharing class Receive_Deliverables {
    string tempDels{get; set;}
    string[] deliArray;
    public string DSId{get;set;}
    public String confirmmsg{get;set;}
    public List<Deliverable__c> lstdels;
    boolean isUnreceive = false;
    public string PrevPageUrl = ApexPages.currentPage().getUrl();

public Receive_Deliverables() {      
        DSId= ApexPages.currentPage().getParameters().get('id');
        UnreceiveLines = getUnreceiveLines();
//refreshPage=false;

    }

public Receive_Deliverables(ApexPages.StandardSetController controller) {
        System.debug('Selected deliverables : '+ApexPages.currentPage().getParameters().get('DeliverablesIds'));
        if(ApexPages.currentPage().getParameters().get('DeliverablesIds') != null){
             tempDels= ApexPages.currentPage().getParameters().get('DeliverablesIds');
             deliArray = tempDels.split(',');
             DSId= ApexPages.currentPage().getParameters().get('id');
             UnreceiveLines = getUnreceiveLines();                                             
        }
      
    }


List<Deliverable__c> ConfirmedDels{get;set;}
    Map<Id, Deliverable__c> InvoiceAmount;
    List<Deliverable__c> UnreceiveLines{get;set;}
    public string getDSId(){
     return DSId= ApexPages.currentPage().getParameters().get('id');

    }

public List<Deliverable__c> getConfirmedDels() {
    if(ConfirmedDels == null)
       ConfirmedDels=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Invoice_Date__c,PO_Number__c from Deliverable__c where Id IN : deliArray and (Approval_Status__c =: 'Not Completed' Or Approval_Status__c =: 'Deliverable Completed')];
         System.debug('Confirmed Deliverables: '+ConfirmedDels.size());
              
       return ConfirmedDels ;
    }

public List<Deliverable__c> getUnreceiveLines(){
            if(UnreceiveLines == null )
             UnreceiveLines=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,PO_Number__c from Deliverable__c where Opportunity__c =:DSId and (Approval_Status__c =: 'Deliverable Approved for Payment') ];
     
                return UnreceiveLines;
        }

public Map<Id, Deliverable__c> getInvoiceAmount(){
            if(InvoiceAmount == null){
                InvoiceAmount = new Map<Id, Deliverable__c>();
                for(Deliverable__c del : getConfirmedDels()){              
                   InvoiceAmount.put(del.Id,del);              
                }
            }
            return InvoiceAmount ;
      
       }

public void ReceiveDeliverable(){
   
    try{
        if(ConfirmedDels.size() > 0 ){
        Boolean IsInvoiceAmountGreaterthanDeliAmount = false;
        if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = new List<deliverable__c>();
    }                   
        for(Deliverable__c deli : ConfirmedDels){
                deli.Approval_Status__c = 'Deliverable Completed';
                System.debug('Partial Amount: '+deli.Partial_Amount__c);
                if(deli.Partial_Amount__c == 0){
                        deli.Partial_Amount__c = null;
                }
                if(deli.Partial_Amount__c > deli.Deliverable_Amount__c){                   
                        IsInvoiceAmountGreaterthanDeliAmount = true;
                }
                if(deli.Partial_Amount__c <> null ){
              
                        if(deli.Make_Partial_Payment__c == false){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Please check [Make Partial Payment?]field when you trying to do partail receive'));
                        }
                }
        }
        List<Database.Saveresult> Dbresult;
        if(!IsInvoiceAmountGreaterthanDeliAmount){                     
           Dbresult = Database.update(ConfirmedDels);
        }
        else
        {             
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'You cannot receive deliverable morethan deliverable amount. Invoice Amount should be less than or equal to Deliverable amount.'));
        }
      
           for(Integer i =0;i< ConfirmedDels.size();i++){
         
                if(Dbresult[i].isSuccess()){
                        try{
                        // create the new approval request to submit
                        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                        req.setComments('Submitted for approval. Please approve.');
                        req.setObjectId(ConfirmedDels[i].Id);
                        // submit the approval request for processing
                        Approval.ProcessResult result = Approval.process(req);
                        // display if the reqeust was successful
                        System.debug('Submitted for approval successfully: '+result.isSuccess());                                              
                          UnreceiveLines.add(ConfirmedDels[i]); 
                        }
                        catch(Exception ex){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Unable to Submit the Record , please check the entry criteria.'));
                                 PageReference OppPage = Page.View_List_Of_Deliverables;
 
  

                        }
                }       
          
            }


if(Dbresult[0].isSuccess()){
confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));                       
            }
        }
    }
    catch(Exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = getUnreceiveLines();
    }
   
     
}

public void UnReceiveDeliverable(){
    
    try{     
            if(UnreceiveLines.size()>0){
                   
                for(Deliverable__c del : UnreceiveLines){
                        if(del.IsLocked ){
                                // create the new approval request to submit
                                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();               
                                req.setComments('Submitted for Unreceive deliverable/PO line.');
                                req.setObjectId(del.Id);
                                // submit the approval request for processing
                                Approval.ProcessResult result = Approval.process(req);
                                // display if the reqeust was successful
                                System.debug('Submitted for approval successfully: '+result.isSuccess());
                        }
               
               
                   
                        del.Approval_Status__c ='Not Completed';
                        del.Work_Approved_By__c= null;                    
                        del.Approved_By_Date__c=null;
                        del.Contractor_Invoice__c = null;
                        if(del.Make_Partial_Payment__c){
                                del.Make_Partial_Payment__c=false;
                                del.Partial_Amount__c=Decimal.valueOf('0');
                        }
                   
                }
               update UnreceiveLines;
             
               
            if(UnreceiveLines.size() == 1)
                ApexPages.addmessage(new ApexPages.message( ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverable got Unreceived successfully, Please close the window'));
               
            if(UnreceiveLines.size() >1)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverables got Unreceived successfully , Please close the window'));
           }
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }


}



public PageReference goBack() {
    string id = ApexPages.currentPage().getParameters().get('id');
    PageReference OppPage = Page.View_List_Of_Deliverables;//new PageReference('https://na3.salesforce.com/apex/View_List_Of_Deliverables?id=' + id );
    OppPage.getParameters().put('id', id);
    OppPage.setRedirect(true); 
      return OppPage;
   }



public PageReference RedirectToActualPage(){
       
    PageReference OppPage_actual = new PageReference(PrevPageUrl);
    OppPage_actual.setRedirect(true);
    return OppPage_actual;
}

public PageReference CancelAction(){
string id = ApexPages.currentPage().getParameters().get('id');
PageReference OppPage = new PageReference('/' + id );
OppPage.setRedirect(true);
return OppPage;
}

}
  • April 11, 2014
  • Like
  • 1
Hi Friends,

I am trying to complete 75% test case for below apex calss but I only coverd 36%. Can you please anyone help on this.

public with sharing class Receive_Deliverables {
    string tempDels{get; set;}
    string[] deliArray;
    public string DSId{get;set;}
    public String confirmmsg{get;set;}
    public List<Deliverable__c> lstdels;
    boolean isUnreceive = false;
    public string PrevPageUrl = ApexPages.currentPage().getUrl();
// public Boolean refreshPage {get; set;}


    public Receive_Deliverables() {       
        DSId= ApexPages.currentPage().getParameters().get('id');
        UnreceiveLines = getUnreceiveLines();
//refreshPage=false;

    }



    public Receive_Deliverables(ApexPages.StandardSetController controller) {
        System.debug('Selected deliverables : '+ApexPages.currentPage().getParameters().get('DeliverablesIds'));
        if(ApexPages.currentPage().getParameters().get('DeliverablesIds') != null){
             tempDels= ApexPages.currentPage().getParameters().get('DeliverablesIds');
             deliArray = tempDels.split(',');
             DSId= ApexPages.currentPage().getParameters().get('id');
             UnreceiveLines = getUnreceiveLines();                                              
        }
       
    }
      
    List<Deliverable__c> ConfirmedDels{get;set;}
    Map<Id, Deliverable__c> InvoiceAmount;
    List<Deliverable__c> UnreceiveLines{get;set;}
    public string getDSId(){
     return DSId= ApexPages.currentPage().getParameters().get('id');

    }
    
    public List<Deliverable__c> getConfirmedDels() {
    if(ConfirmedDels == null)
       ConfirmedDels=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Invoice_Date__c,PO_Number__c from Deliverable__c where Id IN : deliArray and (Approval_Status__c =: 'Not Completed' Or Approval_Status__c =: 'Deliverable Completed')];
         System.debug('Confirmed Deliverables: '+ConfirmedDels.size());
               
       return ConfirmedDels ;
    }

        public List<Deliverable__c> getUnreceiveLines(){
            if(UnreceiveLines == null )
             UnreceiveLines=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,PO_Number__c from Deliverable__c where Opportunity__c =:DSId and (Approval_Status__c =: 'Deliverable Approved for Payment') ];
      
                return UnreceiveLines;
        }
      
       
       public Map<Id, Deliverable__c> getInvoiceAmount(){
            if(InvoiceAmount == null){
                InvoiceAmount = new Map<Id, Deliverable__c>();
                for(Deliverable__c del : getConfirmedDels()){               
                   InvoiceAmount.put(del.Id,del);               
                }
            }
            return InvoiceAmount ;
       
       }
      

      
      
public void ReceiveDeliverable(){
    
    try{
        if(ConfirmedDels.size() > 0 ){
        Boolean IsInvoiceAmountGreaterthanDeliAmount = false;
        if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = new List<deliverable__c>();
    }                    
        for(Deliverable__c deli : ConfirmedDels){
                deli.Approval_Status__c = 'Deliverable Completed';
                System.debug('Partial Amount: '+deli.Partial_Amount__c);
                if(deli.Partial_Amount__c == 0){
                        deli.Partial_Amount__c = null;
                }
                if(deli.Partial_Amount__c > deli.Deliverable_Amount__c){                    
                        IsInvoiceAmountGreaterthanDeliAmount = true;
                }
                if(deli.Partial_Amount__c <> null ){
               
                        if(deli.Make_Partial_Payment__c == false){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Please check [Make Partial Payment?]field when you trying to do partail receive'));
                        }
                }
        }
        List<Database.Saveresult> Dbresult;
        if(!IsInvoiceAmountGreaterthanDeliAmount){                      
           Dbresult = Database.update(ConfirmedDels);
        }
        else
        {              
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'You cannot receive deliverable morethan deliverable amount. Invoice Amount should be less than or equal to Deliverable amount.'));
        }
       
           for(Integer i =0;i< ConfirmedDels.size();i++){
          
                if(Dbresult[i].isSuccess()){
                        try{
                        // create the new approval request to submit
                        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                        req.setComments('Submitted for approval. Please approve.');
                        req.setObjectId(ConfirmedDels[i].Id);
                        // submit the approval request for processing
                        Approval.ProcessResult result = Approval.process(req);
                        // display if the reqeust was successful
                        System.debug('Submitted for approval successfully: '+result.isSuccess());                                               
                          UnreceiveLines.add(ConfirmedDels[i]);  
                        }
                        catch(Exception ex){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Unable to Submit the Record , please check the entry criteria.'));
                                 PageReference OppPage = Page.View_List_Of_Deliverables;
  
   

                        }
                }        
           
            }
           
                        //List<Deliverable__c> lstdels =getUnreceiveLines();
           if(Dbresult[0].isSuccess()){
               
                            
                   // if(ConfirmedDels.size() >1)
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully Received in Salesforce. Please click “Close” button to close this window or click “Back to Step 1” button if you want to receive another deliverable.'));
                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.  REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers).\n 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
      //confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';
      //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
                                           // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,ConfirmedDels.size() +' Deliverables got received successfully , Please close the window'));
               
              //  if(ConfirmedDels.size() == 1)
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully Received in Salesforce. Please click “Close” button to close this window or click “Back to Step 1” button if you want to receive another deliverable.'));
                       // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.  REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). \n 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));
      confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';
      ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));                       
            }
        }
    }
    catch(Exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = getUnreceiveLines();
    }
   
     
}

public void UnReceiveDeliverable(){
    
    try{     
            if(UnreceiveLines.size()>0){
                   
                for(Deliverable__c del : UnreceiveLines){
                        if(del.IsLocked ){
                                // create the new approval request to submit
                                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();               
                                req.setComments('Submitted for Unreceive deliverable/PO line.');
                                req.setObjectId(del.Id);
                                // submit the approval request for processing
                                Approval.ProcessResult result = Approval.process(req);
                                // display if the reqeust was successful
                                System.debug('Submitted for approval successfully: '+result.isSuccess());
                        }
               
               
                   
                        del.Approval_Status__c ='Not Completed';
                        del.Work_Approved_By__c= null;                    
                        del.Approved_By_Date__c=null;
                        del.Contractor_Invoice__c = null;
                        if(del.Make_Partial_Payment__c){
                                del.Make_Partial_Payment__c=false;
                                del.Partial_Amount__c=Decimal.valueOf('0');
                        }
                   
                }
               update UnreceiveLines;
             
               
            if(UnreceiveLines.size() == 1)
                ApexPages.addmessage(new ApexPages.message( ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverable got Unreceived successfully, Please close the window'));
               
            if(UnreceiveLines.size() >1)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverables got Unreceived successfully , Please close the window'));
           }
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   //PageReference OppPage = Page.View_List_Of_Deliverables;
  
   // OppPage.getParameters().put('id', ApexPages.currentPage().getParameters().get('id'));
    //OppPage.setRedirect(true); 
    //  return OppPage;
}



public PageReference goBack() {
    string id = ApexPages.currentPage().getParameters().get('id');
    PageReference OppPage = Page.View_List_Of_Deliverables;//new PageReference('https://na3.salesforce.com/apex/View_List_Of_Deliverables?id=' + id );
    OppPage.getParameters().put('id', id);
    OppPage.setRedirect(true); 
      return OppPage;
   }



public PageReference RedirectToActualPage(){
       
    PageReference OppPage_actual = new PageReference(PrevPageUrl);
    OppPage_actual.setRedirect(true);
    return OppPage_actual;
}

public PageReference CancelAction(){
string id = ApexPages.currentPage().getParameters().get('id');
PageReference OppPage = new PageReference('/' + id );
OppPage.setRedirect(true);
return OppPage;
}

}
  • April 10, 2014
  • Like
  • 1
Hi, I was trying to write test case for below class and I was covered 40% only.
Can you please help me to cover for 75% .

public with sharing class Receive_Deliverables {
    string tempDels{get; set;}
    string[] deliArray;
    public string DSId{get;set;}
    public String confirmmsg{get;set;}
    public List<Deliverable__c> lstdels;
    boolean isUnreceive = false;
    public string PrevPageUrl = ApexPages.currentPage().getUrl();

public Receive_Deliverables() {      
        DSId= ApexPages.currentPage().getParameters().get('id');
        UnreceiveLines = getUnreceiveLines();
//refreshPage=false;

    }

public Receive_Deliverables(ApexPages.StandardSetController controller) {
        System.debug('Selected deliverables : '+ApexPages.currentPage().getParameters().get('DeliverablesIds'));
        if(ApexPages.currentPage().getParameters().get('DeliverablesIds') != null){
             tempDels= ApexPages.currentPage().getParameters().get('DeliverablesIds');
             deliArray = tempDels.split(',');
             DSId= ApexPages.currentPage().getParameters().get('id');
             UnreceiveLines = getUnreceiveLines();                                             
        }
      
    }


List<Deliverable__c> ConfirmedDels{get;set;}
    Map<Id, Deliverable__c> InvoiceAmount;
    List<Deliverable__c> UnreceiveLines{get;set;}
    public string getDSId(){
     return DSId= ApexPages.currentPage().getParameters().get('id');

    }

public List<Deliverable__c> getConfirmedDels() {
    if(ConfirmedDels == null)
       ConfirmedDels=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Invoice_Date__c,PO_Number__c from Deliverable__c where Id IN : deliArray and (Approval_Status__c =: 'Not Completed' Or Approval_Status__c =: 'Deliverable Completed')];
         System.debug('Confirmed Deliverables: '+ConfirmedDels.size());
              
       return ConfirmedDels ;
    }

public List<Deliverable__c> getUnreceiveLines(){
            if(UnreceiveLines == null )
             UnreceiveLines=[select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,PO_Number__c from Deliverable__c where Opportunity__c =:DSId and (Approval_Status__c =: 'Deliverable Approved for Payment') ];
     
                return UnreceiveLines;
        }

public Map<Id, Deliverable__c> getInvoiceAmount(){
            if(InvoiceAmount == null){
                InvoiceAmount = new Map<Id, Deliverable__c>();
                for(Deliverable__c del : getConfirmedDels()){              
                   InvoiceAmount.put(del.Id,del);              
                }
            }
            return InvoiceAmount ;
      
       }

public void ReceiveDeliverable(){
   
    try{
        if(ConfirmedDels.size() > 0 ){
        Boolean IsInvoiceAmountGreaterthanDeliAmount = false;
        if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = new List<deliverable__c>();
    }                   
        for(Deliverable__c deli : ConfirmedDels){
                deli.Approval_Status__c = 'Deliverable Completed';
                System.debug('Partial Amount: '+deli.Partial_Amount__c);
                if(deli.Partial_Amount__c == 0){
                        deli.Partial_Amount__c = null;
                }
                if(deli.Partial_Amount__c > deli.Deliverable_Amount__c){                   
                        IsInvoiceAmountGreaterthanDeliAmount = true;
                }
                if(deli.Partial_Amount__c <> null ){
              
                        if(deli.Make_Partial_Payment__c == false){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Please check [Make Partial Payment?]field when you trying to do partail receive'));
                        }
                }
        }
        List<Database.Saveresult> Dbresult;
        if(!IsInvoiceAmountGreaterthanDeliAmount){                     
           Dbresult = Database.update(ConfirmedDels);
        }
        else
        {             
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'You cannot receive deliverable morethan deliverable amount. Invoice Amount should be less than or equal to Deliverable amount.'));
        }
      
           for(Integer i =0;i< ConfirmedDels.size();i++){
         
                if(Dbresult[i].isSuccess()){
                        try{
                        // create the new approval request to submit
                        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
                        req.setComments('Submitted for approval. Please approve.');
                        req.setObjectId(ConfirmedDels[i].Id);
                        // submit the approval request for processing
                        Approval.ProcessResult result = Approval.process(req);
                        // display if the reqeust was successful
                        System.debug('Submitted for approval successfully: '+result.isSuccess());                                              
                          UnreceiveLines.add(ConfirmedDels[i]); 
                        }
                        catch(Exception ex){
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Unable to Submit the Record , please check the entry criteria.'));
                                 PageReference OppPage = Page.View_List_Of_Deliverables;
 
  

                        }
                }       
          
            }


if(Dbresult[0].isSuccess()){
confirmmsg='You have successfully received in Salesforce. Please click “Close” button to close this window or click “Receive another Deliverable” button if you want to receive another deliverable.';

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'REMINDER: 1.When contractor sends you the invoice, label invoice with PO number '+ConfirmedDels[0].PO_Number__c+' and send to AP. Payment will not be released unless invoice is validated by AP. (Except ERS Suppliers). 2. Upload a sofy copy of the invoice to the Deliverable record (click 5 digits deliverable number auto to go into the deliverable record) for archiving purpose. Scroll down to Notes & Attachements section and click Attach File.'));                       
            }
        }
    }
    catch(Exception e){
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }
   
   if(UnreceiveLines == null || UnreceiveLines.size() == 0){
                UnreceiveLines = getUnreceiveLines();
    }
   
     
}

public void UnReceiveDeliverable(){
    
    try{     
            if(UnreceiveLines.size()>0){
                   
                for(Deliverable__c del : UnreceiveLines){
                        if(del.IsLocked ){
                                // create the new approval request to submit
                                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();               
                                req.setComments('Submitted for Unreceive deliverable/PO line.');
                                req.setObjectId(del.Id);
                                // submit the approval request for processing
                                Approval.ProcessResult result = Approval.process(req);
                                // display if the reqeust was successful
                                System.debug('Submitted for approval successfully: '+result.isSuccess());
                        }
               
               
                   
                        del.Approval_Status__c ='Not Completed';
                        del.Work_Approved_By__c= null;                    
                        del.Approved_By_Date__c=null;
                        del.Contractor_Invoice__c = null;
                        if(del.Make_Partial_Payment__c){
                                del.Make_Partial_Payment__c=false;
                                del.Partial_Amount__c=Decimal.valueOf('0');
                        }
                   
                }
               update UnreceiveLines;
             
               
            if(UnreceiveLines.size() == 1)
                ApexPages.addmessage(new ApexPages.message( ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverable got Unreceived successfully, Please close the window'));
               
            if(UnreceiveLines.size() >1)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,UnreceiveLines.size() +' Deliverables got Unreceived successfully , Please close the window'));
           }
    }
    catch(Exception e){
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR  ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));
    }


}



public PageReference goBack() {
    string id = ApexPages.currentPage().getParameters().get('id');
    PageReference OppPage = Page.View_List_Of_Deliverables;//new PageReference('https://na3.salesforce.com/apex/View_List_Of_Deliverables?id=' + id );
    OppPage.getParameters().put('id', id);
    OppPage.setRedirect(true); 
      return OppPage;
   }



public PageReference RedirectToActualPage(){
       
    PageReference OppPage_actual = new PageReference(PrevPageUrl);
    OppPage_actual.setRedirect(true);
    return OppPage_actual;
}

public PageReference CancelAction(){
string id = ApexPages.currentPage().getParameters().get('id');
PageReference OppPage = new PageReference('/' + id );
OppPage.setRedirect(true);
return OppPage;
}

}
  • April 11, 2014
  • Like
  • 1

Hi, I was trying to write test case for below class and I was covered 40% only.

Can you please help me to cover for 75% . thanks.

 

public

withsharingclassConfirm_UnreceiveDeliverables {

 

List<

Deliverable__c> Confirm_unReceiveDels{get; set;}

string[] deliverableArray;

string tempDels{

get; set;}

 

public string oppId='';

 

publicConfirm_UnreceiveDeliverables() {

oppId= ApexPages.currentPage().getParameters().

get('id');

tempDels= ApexPages.currentPage().getParameters().

get('DeliverablesIds');

 

if(tempDels <> null){

deliverableArray = tempDels.split(

',');

getConfirm_unReceiveDels();

}

}

publicConfirm_UnreceiveDeliverables(ApexPages.StandardSetController controller) {

oppId= ApexPages.currentPage().getParameters().

get('id');

tempDels= ApexPages.currentPage().getParameters().

get('DeliverablesIds');

 

if(tempDels <> null){

deliverableArray = tempDels.split(

',');

getConfirm_unReceiveDels();

}

}

public List<Deliverable__c> getConfirm_unReceiveDels() {

 

if(Confirm_unReceiveDels == null) Confirm_unReceiveDels = [select id,IsLocked,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c fromDeliverable__cwhere Id IN:deliverableArray ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment')returnConfirm_unReceiveDels ;

}

publicvoidUnReceiveDeliverable(){

 

try{ List<Deliverable__c> unReceivedDels = new List<Deliverable__c>();

Integer[] k =

newInteger[]{};

Integer j = 0;

if(Confirm_unReceiveDels.size()>0){

 

for(Deliverable__cdel : Confirm_unReceiveDels){

del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c =

true;

 

if(del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c){

 

// create the new approval request to submitApproval.ProcessSubmitRequest req = newApproval.ProcessSubmitRequest();

req.setComments(

'Submitted for Unreceive deliverable/PO line.');

req.setObjectId(del.Id);

// submit the approval request for processingApproval.ProcessResult result = Approval.process(req);

 

// display if the reqeust was successful

System.debug(

'Submitted for approval successfully: '+result.isSuccess());

}

if(del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c){

k.add(j);

del.Approval_Status__c =

'Not Completed';

del.Work_Approved_By__c=

null;

del.Approved_By_Date__c=

null;

del.Contractor_Invoice__c =

null;

del.Invoice_Date__c =

null;

 

if(del.Make_Partial_Payment__c){

del.Make_Partial_Payment__c=

false;

del.Partial_Amount__c=Decimal.valueOf(

'0');

}

del.Notify_DS_Owner_for_PO_TroubleShoot_Del__c =

false;

unReceivedDels.Add(del);

}

j++;

}

updateunReceivedDels;

 

//for(Integer i : k){//if(unReceiveDels[i].Notify_DS_Owner_for_PO_TroubleShoot_Del__c){//unReceiveDels.remove(i);//} //}if(unReceivedDels.size() >1)

ApexPages.addmessage(

new ApexPages.message(ApexPages.severity.confirm,'You have successfully UnReceived in Salesforce. Please click “Close” button to close this window or click “UnReceive another deliverable” button if you want to unreceive another deliverable.'));

 

if(unReceivedDels.size() == 1)

ApexPages.addmessage(

new ApexPages.message(ApexPages.severity.confirm,'You have successfully UnReceived in Salesforce. Please click “Close” button to close this window or click “UnReceive another deliverable” button if you want to unreceive another deliverable.'));

 

}

}

catch(Exception e){

ApexPages.addmessage(

new ApexPages.message(ApexPages.severity.ERROR ,'Following error occured while Receiving '+ ApexPages.currentPage().getParameters().get('id')+ e));

}

 

}

public

PageReference goBack()

{

string id = ApexPages.currentPage().getParameters().

get('id');

PageReference OppPage = Page.Un_Receive_Deliverables;

////PageReference('https://cs3.salesforce.com/apex/Un_Receive_Deliverables?&id=' + oppId);

OppPage.getParameters().put(

'id', id);

OppPage.setRedirect(

true);

 

returnOppPage;

 

}

publicPageReference CancelAction(){

string id = ApexPages.currentPage().getParameters().

get('id');

PageReference OppPage =

new PageReference('https://na3.salesforce.com/'+ oppId);

OppPage.setRedirect(

true);

 

returnOppPage;

}

 

 

}

 

 

  • December 13, 2013
  • Like
  • 0

Hi all,

 

I'm a Salesforce developer with 2 years of experience. Recently i've decided to give my certification. I have found that even after 2 years of experience i find many questions in dumps difficult to answer.

 

Is creating the Recruitment app essential to crack the exam?  I also found I need to memorise  a lot of numerical data related to salesforce Limits.

 

My friend suggested that going through all of the dumps available is enough to crack the exam. Is it enough if i go through all the available dumps and learn the ones i couldnt answer ?

 

Please let me know as i'm deciding to give the exam by next week.

 

Hi I am trying to write test case for below class file. CAn any one help me ?

 Thanks.

 

public with sharing class ListOf_Deliverables { public string oppId=''; public ListOf_Deliverables(ApexPages.StandardSetController controller) { oppId= ApexPages.currentPage().getParameters().get('id'); //getDels(); } public ListOf_Deliverables() { oppId= ApexPages.currentPage().getParameters().get('id'); getDels(); } public void setOppId(string DSId){ oppId = DSId; } string UrltoOpen {get;set;} List<Deliverable__c> dels{get; set;} List<Deliverable__c> unReceiveDels{get; set;} public string getUrltoOpen(){ if(UrltoOpen == null || UrltoOpen == ''){ UrltoOpen = 'httpss://cs13.salesforce.com/apex/Receive_Deliverables?scontrolCaching=1&id=' + ApexPages.currentPage().getParameters().get('id') + '&DeliverablesIds='; } return UrltoOpen; } public List<Deliverable__c> getDels() { if(dels == null) dels = [select id,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c from Deliverable__c where ((Approval_Status__c =: 'Not Completed') and Extracted__c =: true) and Update__c =: 'U' and PO_Number__c <> null and Opportunity__c =:oppId ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment') return dels ; } public List<Deliverable__c> getUnReceiveDels() { if(unReceiveDels == null) unReceiveDels = [select id,Name,Amount_Paid__c,Balance__c,Deliverable_Number__c,Partial_Amount__c,Make_Partial_Payment__c,Notify_DS_Owner_for_PO_TroubleShoot_Del__c,Work_Approved_By__c,Approved_By_Date__c,Contractor_Invoice__c, Deliverable_Amount__c,due_date__c,Approval_Status__c,Deliverable_Description__c,Opportunity__c from Deliverable__c where (Approval_Status__c =: 'Deliverable Approved for Payment' and (Extracted__c =: true OR Make_Partial_Payment__c =: true )) and Update__c =: 'U' and PO_Number__c <> null and Opportunity__c =:oppId ];//OR (Approval_Status__c =: 'Deliverable Approved for Payment') return unReceiveDels ; } public PageReference ConfirmAction(){ string Del_Id=null; if(dels != null){ for(integer count=0; count< dels.size();count++) { if(dels[count].Notify_DS_Owner_for_PO_TroubleShoot_Del__c == true) { if(Del_Id != null){ Del_Id = Del_Id + dels[count].Id +','; } else{ Del_Id = dels[count].Id +','; } } } } if(unReceiveDels != null){ for(integer count=0; count< unReceiveDels.size();count++) { if(unReceiveDels[count].Notify_DS_Owner_for_PO_TroubleShoot_Del__c == true) { if(Del_Id != null){ Del_Id = Del_Id + unReceiveDels[count].Id +','; } else{ Del_Id = unReceiveDels[count].Id +','; } } } } string id = ApexPages.currentPage().getParameters().get('id'); UrltoOpen = UrltoOpen+Del_Id; PageReference OppPage = new PageReference('/apex/Receive_Deliverables?scontrolCaching=1&id=' + id + '&DeliverablesIds='+Del_Id); OppPage.setRedirect(true); return OppPage; } public PageReference CancelAction(){ string id = ApexPages.currentPage().getParameters().get('id'); PageReference OppPage = new PageReference('https://cs3.salesforce.com/' + oppId); OppPage.setRedirect(true); return OppPage; }}

  • September 21, 2012
  • Like
  • 0

Hi,

 

I wanted to hide custom button in standard objects detail page. So I did by implementing s-control and I made JavaScript code changes for it. Actually I can hide the button when the page first time loading but I count hide it when the refresh same page and its getting error out as following: 'window.parent.document.getElementsByName(...).0.style' is null or not an object.

 

var e=window.parent.document.getElementsByName("unreceive_deliverable1");
alert(" The count of button " + e.length);
e[0].style.display="none";

 

- unreceive_deliverable1 - is the button name

- I am getting count value is 1 when the page first time loading but getting 0 if I refresh the same page.

 

I am not sure where it is missing.  Please let me know if you have any question?

 

I appreciate if you could help me on this.

 

Thanks,

Mahendiran.

 

  • August 30, 2012
  • Like
  • 0

System.DmlException: Update failed. First exception on row 0 with id 0065000000JfoKmAAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoReceiveDeliverable: execution of BeforeUpdate

 

caused by: System.DmlException: Process failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectDeliverableTrigger: execution of BeforeUpdate

 

caused by: System.Exception: Too many SOQL queries: 101

 

Class.DeliverableProject.ProjectApprovers: line 52, column 1

Trigger.ProjectDeliverableTrigger: line 35, column 1: []

 

Trigger.AutoReceiveDeliverable: line 59, column 1

 

Class.SyncPONumberOnDealSheet.updateDealSheetPONumber_list: line 38, column 1

  • June 15, 2012
  • Like
  • 0

I write a apex class to import csv file from the VF page. The 'BLOB is not a valid UTF-8 string' raising.I don't how to set the csv encode. or is there any way to convert the file to UTF-8 by apex code.

Any suggestion would be appriciate.

Thanks.

  • May 16, 2012
  • Like
  • 0