• Salvatore Gomez
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
The inbound email handler below works when the email address in the body is passed as plaintext. However, the email address in the body is usually in the format of an mailto link which prevents the submission of this lead. How can i convert the email address that is contained in the email body to plain text?

global class ProcessJobApplicantEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    String RecordTypeId = '01280000000BWjJAAW';
    String status = 'Open - New';
    String LeadSource ='Referral';
    String SecondLeadSource = 'Online Division';
    String[] emailBody = email.plainTextBody.split('\n', 0);
    String FirstName = emailBody[0].substring(11);
    String LastName = emailBody[1].substring(10);
    String EmailAddress =  emailBody[2].substring(14);
    String Phone = emailBody[3].substring(6);
  
    Lead Lead = new Lead();
    Lead.FirstName=FirstName;
    Lead.LastName=LastName;
    Lead.Phone= Phone;
    Lead.Email=EmailAddress;
    Lead.RecordTypeId= RecordTypeId;
    Lead.status=status;
    Lead.LeadSource=LeadSource;
    Lead.Lead_Source_2__c=SecondLeadSource;
    insert Lead;
    
    System.debug('====> Created lead '+Lead.Id);

    return result;

  }

}

Thanks for your help
I always seem to struggle with returning data fields from Multiple sobject in single query to visualforce page. Every time i try to display one of the opportunity fields in a visualforce page with a query similar to below i always get a invalid field for sobject error which I get because the list type is an account. I'm just trying to understand what is the best method for retrieving the result set from the below query and displaying it in visualforce. any help is greatly appreciated, thanks in advanced.

List<Account> Acc = new List<Account>();

Acc = [SELECT Id,Name,PersonEmail
 ,(Select Attachment.Id, Attachment.ParentId from Account.Attachments where Name='Contact Picture',(SELECT Opportunity.PLAN_DESCR__c,Opportunity.ADMIT_TERM_DESCR__c,Opportunity.JOB_TITLE__c,Opportunity.AccountId FROM Account.Opportunities)
            FROM Account Where Id in
                (SELECT AccountId FROM Opportunity where PLAN_DESCR__c='Business Analytics' and ADMIT_TERM_DESCR__c='2016 Fall')
            limit 20                 
     ];
Fair warning i'm an Apex Noob. I'm getting a List index out of bounds: 1 error on the code below. It seems like the issue is with the Att list since the query may or may not return an attachment for each account. Of course i could be wrong on that any suggestions on how to rework this would be greatly appreciated.

Apex code:
Public class PhotoWrapper{
List<Account> Acc = new List<Account>();
List<Opportunity> Opp = new List<Opportunity>();
List<wrapper> lstw = new List<wrapper>();
List<Attachment> Att = new List<Attachment>();
Public List<wrapper> getLstWrapperString()
{
    Acc=[SELECT Id,Name,PersonEmail,(Select Id, ParentId from Attachments where Name='Contact Picture') FROM Account limit 20];
    Att=[Select Id, ParentId from Attachment where Name='Contact Picture' and ParentId in :Acc];
    Opp=[SELECT PLAN_DESCR__c,ADMIT_TERM_DESCR__c,JOB_TITLE__c, AccountId FROM Opportunity where AccountId in : Acc];
    for(integer i=0;i<Acc.size();i++)
    {
        lstw.add(new wrapper(Acc[i].Id,Acc[i].name, Acc[i].PersonEmail,Opp[i].PLAN_DESCR__c,Opp[i].ADMIT_TERM_DESCR__c,Opp[i].JOB_TITLE__c,Opp[i].AccountId,Att[i].Id));
   }
    return lstw;
}

Public class wrapper{
    Public String Aname {get;set;}
    Public String Aemail {get;set;}
    Public String OPLAN_DESCR {get;set;}
    Public String OADMIT_TERM {get;set;}
    Public String OJOB_TITLE {get;set;}
    Public String AccId {get;set;}
    Public String OAccId {get;set;}
    Public String AttId {get;set;}

Public wrapper(String AccId,String Aname, String Aemail,String OPLAN_DESCR, String OADMIT_TERM,String OJOB_TITLE, String OAccId,String AttId){
     this.Aname=Aname;
     this.Aemail=Aemail;
     this.OPLAN_DESCR=OPLAN_DESCR;
     this.OADMIT_TERM = OADMIT_TERM;
     this.OJOB_TITLE = OJOB_TITLE;
     AccId=OAccId;
     this.AttId=AttId;
 }

}
}
Hello all,
 I'm trying to retrieve the latest attachment from Job_Applicants__c and the latest attachment from from Applied_Applicants__c and combine into a single blocktable row. The requirement i'm trying to achieve is that a job applicant can attach a resume to their account record but they need to attach a customized cover letter for each job they apply to. So far i'm just tampering around with soql code so any suggestions are very much appreciated.

  Records = [Select Name,First_Name__c,Last_Name__c, (Select Id, LastModifiedDate From Attachments Order By LastModifiedDate DESC)
                 From Job_Applicants__c t where Id in (select Applicant__c from Applied_Applicants__c where JobPosting__c=:A and Status__c not in    ('Offered','Taken'))];

   Applicants =[Select Id, (Select Id, LastModifiedDate From Attachments Order By LastModifiedDate DESC)
                   from Applied_Applicants__c where JobPosting__c=:A and Status__c not in ('Offered','Taken')];
I seem to be struggling with my unit testing for this class. I can't seem to get past a 57% code coverage with my current unit test so I know i'm missing something but i just can't figure it out. Everything in bold in the unit test below is not being tested and i have tried multiple scenarios that just don't seem to cover it. I'm wondering if re-working the class would be a better option. Any thoughts or suggestions? Thank you.

public class InputFileControllerExtension {
 
   private final Job_Applicants__c app;
   public Attachment attachment {get;set;}  
   public PageReference save() {
   
     try{
     insert app;
     attachment.parentid = app.id;
     insert attachment;
     return stdController.save();

 
     
     PageReference confirmPage = Page.GA_ApplicantConfirmation;
     confirmPage.setRedirect(true);
     return confirmPage;

     }Catch(DmlException e){
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'an account has already been created for that ASURITE');
                ApexPages.addMessage(myMsg);

     
     }
     Catch(Exception e){
         ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'an error has occurred please contact wpcarey.support@asu.edu');
                ApexPages.addMessage(myMsg);

     }
        Return null;
   
   }
   
   
 
 public InputFileControllerExtension(ApexPages.StandardController stdController)
 {
 
  attachment = new Attachment();
  this.app = (Job_Applicants__c)stdController.getRecord();
  this.stdController = stdController;
 }
 
 ApexPages.StandardController stdController;
}

=========================================
@isTest
private class InputTest {

    static testMethod void InputFileTest() {
    
    Job_Applicants__c Applicant = new Job_Applicants__c();
    
    Applicant.ASURITE__c='Test';
    
    Insert Applicant;
    
    Attachment attach=new Attachment();    
    attach.Name='Unit Test Attachment';
    Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    attach.body=bodyBlob;
    attach.parentId=Applicant.id;
    attach.ContentType = 'application/msword';
    attach.IsPrivate = false;
    attach.Description = 'Test';
    insert attach;
    
    Attachment testAtt = [Select ParentId from Attachment where Id =:attach.Id];
    
    System.assertEquals(Applicant.Id,testAtt.ParentId);
 
    Test.startTest();
    ApexPages.StandardController sc = new ApexPages.StandardController(Applicant);
    InputFileControllerExtension Inp = new InputFileControllerExtension(sc);
    PageReference pageRef = Page.GA_CreateApplicant; // Add your VF page Name here
    pageRef.getParameters().put('id', String.valueOf(Applicant.Id));
    Test.setCurrentPage(pageRef);
    Inp.save();
    Test.stopTest();
    
    System.assertEquals(testAtt, Inp.attachment);
    
        
    }
}
The inbound email handler below works when the email address in the body is passed as plaintext. However, the email address in the body is usually in the format of an mailto link which prevents the submission of this lead. How can i convert the email address that is contained in the email body to plain text?

global class ProcessJobApplicantEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    String RecordTypeId = '01280000000BWjJAAW';
    String status = 'Open - New';
    String LeadSource ='Referral';
    String SecondLeadSource = 'Online Division';
    String[] emailBody = email.plainTextBody.split('\n', 0);
    String FirstName = emailBody[0].substring(11);
    String LastName = emailBody[1].substring(10);
    String EmailAddress =  emailBody[2].substring(14);
    String Phone = emailBody[3].substring(6);
  
    Lead Lead = new Lead();
    Lead.FirstName=FirstName;
    Lead.LastName=LastName;
    Lead.Phone= Phone;
    Lead.Email=EmailAddress;
    Lead.RecordTypeId= RecordTypeId;
    Lead.status=status;
    Lead.LeadSource=LeadSource;
    Lead.Lead_Source_2__c=SecondLeadSource;
    insert Lead;
    
    System.debug('====> Created lead '+Lead.Id);

    return result;

  }

}

Thanks for your help
I always seem to struggle with returning data fields from Multiple sobject in single query to visualforce page. Every time i try to display one of the opportunity fields in a visualforce page with a query similar to below i always get a invalid field for sobject error which I get because the list type is an account. I'm just trying to understand what is the best method for retrieving the result set from the below query and displaying it in visualforce. any help is greatly appreciated, thanks in advanced.

List<Account> Acc = new List<Account>();

Acc = [SELECT Id,Name,PersonEmail
 ,(Select Attachment.Id, Attachment.ParentId from Account.Attachments where Name='Contact Picture',(SELECT Opportunity.PLAN_DESCR__c,Opportunity.ADMIT_TERM_DESCR__c,Opportunity.JOB_TITLE__c,Opportunity.AccountId FROM Account.Opportunities)
            FROM Account Where Id in
                (SELECT AccountId FROM Opportunity where PLAN_DESCR__c='Business Analytics' and ADMIT_TERM_DESCR__c='2016 Fall')
            limit 20                 
     ];
Fair warning i'm an Apex Noob. I'm getting a List index out of bounds: 1 error on the code below. It seems like the issue is with the Att list since the query may or may not return an attachment for each account. Of course i could be wrong on that any suggestions on how to rework this would be greatly appreciated.

Apex code:
Public class PhotoWrapper{
List<Account> Acc = new List<Account>();
List<Opportunity> Opp = new List<Opportunity>();
List<wrapper> lstw = new List<wrapper>();
List<Attachment> Att = new List<Attachment>();
Public List<wrapper> getLstWrapperString()
{
    Acc=[SELECT Id,Name,PersonEmail,(Select Id, ParentId from Attachments where Name='Contact Picture') FROM Account limit 20];
    Att=[Select Id, ParentId from Attachment where Name='Contact Picture' and ParentId in :Acc];
    Opp=[SELECT PLAN_DESCR__c,ADMIT_TERM_DESCR__c,JOB_TITLE__c, AccountId FROM Opportunity where AccountId in : Acc];
    for(integer i=0;i<Acc.size();i++)
    {
        lstw.add(new wrapper(Acc[i].Id,Acc[i].name, Acc[i].PersonEmail,Opp[i].PLAN_DESCR__c,Opp[i].ADMIT_TERM_DESCR__c,Opp[i].JOB_TITLE__c,Opp[i].AccountId,Att[i].Id));
   }
    return lstw;
}

Public class wrapper{
    Public String Aname {get;set;}
    Public String Aemail {get;set;}
    Public String OPLAN_DESCR {get;set;}
    Public String OADMIT_TERM {get;set;}
    Public String OJOB_TITLE {get;set;}
    Public String AccId {get;set;}
    Public String OAccId {get;set;}
    Public String AttId {get;set;}

Public wrapper(String AccId,String Aname, String Aemail,String OPLAN_DESCR, String OADMIT_TERM,String OJOB_TITLE, String OAccId,String AttId){
     this.Aname=Aname;
     this.Aemail=Aemail;
     this.OPLAN_DESCR=OPLAN_DESCR;
     this.OADMIT_TERM = OADMIT_TERM;
     this.OJOB_TITLE = OJOB_TITLE;
     AccId=OAccId;
     this.AttId=AttId;
 }

}
}
Hello all,
 I'm trying to retrieve the latest attachment from Job_Applicants__c and the latest attachment from from Applied_Applicants__c and combine into a single blocktable row. The requirement i'm trying to achieve is that a job applicant can attach a resume to their account record but they need to attach a customized cover letter for each job they apply to. So far i'm just tampering around with soql code so any suggestions are very much appreciated.

  Records = [Select Name,First_Name__c,Last_Name__c, (Select Id, LastModifiedDate From Attachments Order By LastModifiedDate DESC)
                 From Job_Applicants__c t where Id in (select Applicant__c from Applied_Applicants__c where JobPosting__c=:A and Status__c not in    ('Offered','Taken'))];

   Applicants =[Select Id, (Select Id, LastModifiedDate From Attachments Order By LastModifiedDate DESC)
                   from Applied_Applicants__c where JobPosting__c=:A and Status__c not in ('Offered','Taken')];
I seem to be struggling with my unit testing for this class. I can't seem to get past a 57% code coverage with my current unit test so I know i'm missing something but i just can't figure it out. Everything in bold in the unit test below is not being tested and i have tried multiple scenarios that just don't seem to cover it. I'm wondering if re-working the class would be a better option. Any thoughts or suggestions? Thank you.

public class InputFileControllerExtension {
 
   private final Job_Applicants__c app;
   public Attachment attachment {get;set;}  
   public PageReference save() {
   
     try{
     insert app;
     attachment.parentid = app.id;
     insert attachment;
     return stdController.save();

 
     
     PageReference confirmPage = Page.GA_ApplicantConfirmation;
     confirmPage.setRedirect(true);
     return confirmPage;

     }Catch(DmlException e){
     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'an account has already been created for that ASURITE');
                ApexPages.addMessage(myMsg);

     
     }
     Catch(Exception e){
         ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'an error has occurred please contact wpcarey.support@asu.edu');
                ApexPages.addMessage(myMsg);

     }
        Return null;
   
   }
   
   
 
 public InputFileControllerExtension(ApexPages.StandardController stdController)
 {
 
  attachment = new Attachment();
  this.app = (Job_Applicants__c)stdController.getRecord();
  this.stdController = stdController;
 }
 
 ApexPages.StandardController stdController;
}

=========================================
@isTest
private class InputTest {

    static testMethod void InputFileTest() {
    
    Job_Applicants__c Applicant = new Job_Applicants__c();
    
    Applicant.ASURITE__c='Test';
    
    Insert Applicant;
    
    Attachment attach=new Attachment();    
    attach.Name='Unit Test Attachment';
    Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    attach.body=bodyBlob;
    attach.parentId=Applicant.id;
    attach.ContentType = 'application/msword';
    attach.IsPrivate = false;
    attach.Description = 'Test';
    insert attach;
    
    Attachment testAtt = [Select ParentId from Attachment where Id =:attach.Id];
    
    System.assertEquals(Applicant.Id,testAtt.ParentId);
 
    Test.startTest();
    ApexPages.StandardController sc = new ApexPages.StandardController(Applicant);
    InputFileControllerExtension Inp = new InputFileControllerExtension(sc);
    PageReference pageRef = Page.GA_CreateApplicant; // Add your VF page Name here
    pageRef.getParameters().put('id', String.valueOf(Applicant.Id));
    Test.setCurrentPage(pageRef);
    Inp.save();
    Test.stopTest();
    
    System.assertEquals(testAtt, Inp.attachment);
    
        
    }
}