• ki
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
List<Target_item__c> ti_list = [select id,PO_Number__c,UPC__c,Target_PO__c from Target_item__c];
               //List<Target_po__c> poitem = [select id,PO_Number__c from Target_po__c];
               List<Target_item__c> tii_list = new List<Target_item__c>();
               Target_item__c ti_upsert = new Target_item__c();
               Integer xi=0;
               
               if(ti_list.size() > 0){
                   for(Integer i = titoupload.size() - 1; i >= 0 ; --i){
                       for(Integer j = ti_list.size() - 1; j >= 0 ; --j){
                           //md.debug('---i---'+i);
                           //md.debug('---j---'+j);                        
                           if((titoupload[i].PO_Number__c == ti_list[j].PO_Number__c)&&(titoupload[i].UPC__c == ti_list[j].UPC__c)){  
                               String po_num = titoupload[i].PO_Number__c;
                               String upc_num = titoupload[i].UPC__c; 
                               //Target_item__c ti_upsert = [select id from Target_item__c where Po_Number__c =: po_num AND UPC__c =: upc_num limit 1];
                               
                               ti_upsert.id = ti_list[j].id;
                               ti_upsert.PO_Number__c = ti_list[j].PO_Number__c;
                               ti_upsert.UPC__c = ti_list[j].UPC__c;
                               ti_upsert.Case_Pack__c = titoupload[i].Case_Pack__c;
                               ti_upsert.Target_Item__c = titoupload[i].Target_Item__c;
                               ti_upsert.Description__c = titoupload[i].Description__c;
                               ti_upsert.Color__c = titoupload[i].Color__c;
                               ti_upsert.Size__c = titoupload[i].Size__c;
                               ti_upsert.Price__c = titoupload[i].Price__c;
                               ti_upsert.Retail_Price__c = titoupload[i].Retail_Price__c;
                               ti_upsert.Ordered_Qty__c = titoupload[i].Ordered_Qty__c;
                               ti_upsert.Ship_Qty__c = titoupload[i].Ship_Qty__c;
                               ti_upsert.Target_PO__c = ti_list[j].Target_PO__c;
                               ti_upsert.BG_Product__c = titoupload[i].BG_Product__c;
                               
                               tii_list.add(ti_upsert);
  • January 08, 2017
  • Like
  • 0
List<Target_item__c> ti_list = [select id,PO_Number__c,UPC__c,Target_PO__c from Target_item__c];
               //List<Target_po__c> poitem = [select id,PO_Number__c from Target_po__c];
               List<Target_item__c> tii_list = new List<Target_item__c>();
               Target_item__c ti_upsert = new Target_item__c();
               Integer xi=0;
               
               if(ti_list.size() > 0){
                   for(Integer i = titoupload.size() - 1; i >= 0 ; --i){
                       for(Integer j = ti_list.size() - 1; j >= 0 ; --j){
                           //md.debug('---i---'+i);
                           //md.debug('---j---'+j);                        
                           if((titoupload[i].PO_Number__c == ti_list[j].PO_Number__c)&&(titoupload[i].UPC__c == ti_list[j].UPC__c)){  
                               String po_num = titoupload[i].PO_Number__c;
                               String upc_num = titoupload[i].UPC__c; 
                               //Target_item__c ti_upsert = [select id from Target_item__c where Po_Number__c =: po_num AND UPC__c =: upc_num limit 1];
                               
                               ti_upsert.id = ti_list[j].id;
                               ti_upsert.PO_Number__c = ti_list[j].PO_Number__c;
                               ti_upsert.UPC__c = ti_list[j].UPC__c;
                               ti_upsert.Case_Pack__c = titoupload[i].Case_Pack__c;
                               ti_upsert.Target_Item__c = titoupload[i].Target_Item__c;
                               ti_upsert.Description__c = titoupload[i].Description__c;
                               ti_upsert.Color__c = titoupload[i].Color__c;
                               ti_upsert.Size__c = titoupload[i].Size__c;
                               ti_upsert.Price__c = titoupload[i].Price__c;
                               ti_upsert.Retail_Price__c = titoupload[i].Retail_Price__c;
                               ti_upsert.Ordered_Qty__c = titoupload[i].Ordered_Qty__c;
                               ti_upsert.Ship_Qty__c = titoupload[i].Ship_Qty__c;
                               ti_upsert.Target_PO__c = ti_list[j].Target_PO__c;
                               ti_upsert.BG_Product__c = titoupload[i].BG_Product__c;
                               
                               tii_list.add(ti_upsert);
  • January 08, 2017
  • Like
  • 0

hello All,

 

Here I'm again with some un-coverage issue for Apex In-BoundEmailService class in sfdc.

 

Here is myInbound emailservice class-

 

global class inBoundEmail implements Messaging.InboundEmailHandler
{
   global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
   {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String subToCompare = 'Create Contact';

        if(email.subject.equalsIgnoreCase(subToCompare))
        {
            Contact c = new Contact();
            c.Email=email.fromAddress;
            
            // capture phone number and city also from incoming email.
            // Splits each line by the terminating newline character  
            // and looks for the position of the phone number and city 
            String[] emailBody = email.plainTextBody.split('\n', 0);
            c.LastName=emailBody[0].substring(0);
            c.Phone = emailBody[1].substring(0);
            c.Title = emailBody[2].substring(0);
                       
            insert c;
            
            // Save attachments, if any
            if (email.textAttachments != null)
            {
            for(Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments)
            {
            Attachment attachment = new Attachment();

            attachment.Name = tAttachment.fileName;
            attachment.Body = Blob.valueOf(tAttachment.body);
            attachment.ParentId = c.Id;
            insert attachment;
            }
            
            }

            //Save any Binary Attachment
            
            if (email.binaryAttachments != null)
            {
            for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
            Attachment attachment = new Attachment();

            attachment.Name = bAttachment.fileName;
            attachment.Body = bAttachment.body;
            attachment.ParentId = c.Id;
            insert attachment;
            }
           } 
        }

        result.success = true;
        return result;
             
   }
   }

Thisis the Test Class which is creating no error but it's not covering all test conditions.

 

//Test Method for main class
   
   static testMethod void TestinBoundEmail()
   {
     // create a new email and envelope object
     
   Messaging.InboundEmail email = new Messaging.InboundEmail() ;
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
   
   // setup the data for the email
   
  email.subject = 'Test Job Applicant';
  email.fromAddress = 'someaddress@email.com';
  
  // add an Binary attachment
  
  Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfileone.txt';
  attachment.mimeTypeSubType = 'text/plain';
  email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
 
  // add an Text atatchment
  
  Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfiletwo.txt';
  attachment.mimeTypeSubType = 'texttwo/plain';
  email.textAttachments =   new Messaging.inboundEmail.TextAttachment[] { attachmenttext };
 
  // call the email service class and test it with the data in the testMethod
  inBoundEmail  testInbound=new inBoundEmail ();
  testInbound.handleInboundEmail(email, env);
    
   // create a contact data
   
    Contact testContact= new Contact();
    testContact.Email='someaddress@email.com';
    testContact.LastName='lastname';
    testContact.Phone='1234567234';
    testContact.Title='hello';
    insert testContact;
    
    system.debug('insertedcontact id===>' +testContact.Id);
   
   // Create Attachmenat data
   
  Attachment attachmnt =new Attachment();
  attachmnt.name='textfileone.txt';
  attachmnt.body =blob.valueOf('my attachment text');
  attachmnt.ParentId =testContact.Id;
  insert  attachmnt ;
   
   
   }
   

 

Could any one please make me correct in this case.

 

I tried to put all conditions and test data still it's creating problem.

 

Thanks for your valuable suggestions.

 

Thanks & regards,

jaanVivek