• Vamshi Reddy Bandaru
  • NEWBIE
  • 5 Points
  • Member since 2014
  • Salesforce Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hello,

I am having an issue with my test class adderror on a trigger.

trigger Validation on ObjectA (before update) {
 
        for(ObjectA lstVAdd :  trigger.new){   

            if(lstVAdd.Supplier__c==null && lstVAdd.Status__c=='Closed' && lstVAdd.Comments__c ==null){
        Trigger.new[0].Supplier.addError(My Message);
           
                       }
        }
    }

Thank you
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

Today we’re excited to announce the new Salesforce Developers Discussion Forums. We’ve listened to your feedback on how we can improve the forums.  With Chatter Answers, built on the Salesforce1 Platform, we were able to implement an entirely new experience, integrated with the rest of the Salesforce Developers site.  By the way, it’s also mobile-friendly.

We’ve migrated all the existing data, including user accounts. You can use the same Salesforce account you’ve always used to login right away.  You’ll also have a great new user profile page that will highlight your community activity.  Kudos have been replaced by “liking” a post instead and you’ll now be able to filter solved vs unsolved posts.

This is, of course, only the beginning  and because it’s built on the Salesforce1 Platform, we’re going to be able to bring you more features faster than ever before.  Be sure to share any feedback, ideas, or questions you have on this forum post.

Hats off to our development team who has been working tirelessly over the past few months to bring this new experience to our community. And thanks to each of you for helping to build one of the most vibrant and collaborative developer communities ever.