• Abhishek Kumar 149
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 8
    Replies
  //Set Subject
        subject = (action == '1' || action == '2') ? 'RE: ' : ((action == '3' ) ? 'FW: ' : '');
        System.debug(subject);
        emailBody = '\n\n' + 'Thanks & Regards' + '\n' + currentUserName + '\n';
        
        //IF record Id Present
        if(String.isNotBlank(recordId)){
            List<EmailMessage> emList = [SELECT Id, ToAddress, CcAddress, BccAddress, FromAddress,
                                         FromName, ParentId, ReplyToEmailMessageId, TextBody, Subject,
                                         EBS_FromAddress__c, EBS_Status__c
                                         FROM EmailMessage WHERE Id = :recordId LIMIT 1]; 
            if(!emList.isEmpty()){
                emailMessage = emList.get(0);
                
                if(String.isNotBlank(emailMessage.Subject))
                    subject += emailMessage.Subject;
                                
                if(String.isNotBlank(emailMessage.TextBody))
                    emailBody += emailMessage.TextBody; 
                //For REPLY ALL
                toEmail = '';
                ccEmail = '';
                bccEmail = ''; 
                //For Reply
                if(action == '1' && String.isNotBlank(emailMessage.EBS_FromAddress__c)){
                   toEmail += emailMessage.EBS_FromAddress__c;                    
                }
                //Reply All
                else if(action == '2'){
                    /*
                    if(String.isNotBlank(emailMessage.ToAddress))
                        toEmail += emailMessage.ToAddress;
                        
                    if(String.isNotBlank(emailMessage.EBS_FromAddress__c) 
                            && !toEmail.containsIgnoreCase(emailMessage.EBS_FromAddress__c)){
                        toEmail = emailMessage.EBS_FromAddress__c + ',' + toEmail;    
                    }*/
          toEmail += emailMessage.EBS_FromAddress__c;                     
                    
                    if(String.isNotBlank(emailMessage.CcAddress))
                        ccEmail += emailMessage.CcAddress;
                    
                    if(String.isNotBlank(emailMessage.BccAddress))
                        bccEmail += emailMessage.BccAddress;
                    
                }
                toEmail = toEmail.replace(';', ',');                
                ccEmail = ccEmail.replace(';', ',');
                bccEmail = bccEmail.replace(';', ',');
            }
            //Find attchements when Forwarding
            if(action == '3'){
                List<Attachment> attachedFiles = [SELECT Id, Name, Body, ContentType                                                   
                                                  FROM Attachment 
                                                  WHERE ParentId =: recordId];                
                if(!attachedFiles.isEmpty()){
                    isFW = true;
                    for(Attachment a: attachedFiles){
                        attachmentList.add(new AttachmentInfo(a));    
acc= (id == '1' || id== '2') ? 'a: ' : ((id == '3' ) ? 'b: ' : '');
ApexPages.currentPage().getParameters().get('action'); // 0- > New, 1 -> Reply, 2 -> Reply All, 3 -> Forward
public PageReference sendEmail(){
        
        try{ 
            if(String.isBlank(toEmail)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please enter To Address'));
                
                return null;
            }
            if(String.isBlank(subject)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please enter Subject'));
                        return null;                
            }
 isOutput = false;
        isInput =  false;
        
        parentId = ApexPages.currentPage().getParameters().get('pId');
        recordId = ApexPages.currentPage().getParameters().get('Id');
      
      
        }
        
       
        
public PageReference sendEmail(){
        
        try{ 
            if(String.isBlank(toEmail)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please enter To Address'));
                
                return null;
            }
            if(String.isBlank(subject)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please enter Subject'));
                        return null;                
            }