function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sai Ram ASai Ram A 

Could not achieve Chatter Preview

I have a approval in process to post the attachments to Chatter, 

 

If a record is Approved which is created through UI with attachments, I am able to view the preview of Attachments.

 

I am not able to see the preview of attachments after approval of records  created through inbound email.

 

Is any thing i need to add in the code or?

 

public class EmailParsingActivity {
    
    public void attachToRecord(Messaging.InboundEmail.BinaryAttachment[] bAttachments, ID abcdRecId) {     
        String contents='';                       //ok
        List<Attachment> listAttach = new List<Attachment>();

        if(bAttachments != null) {
            for(Messaging.InboundEmail.BinaryAttachment bAttach : bAttachments){  //ok
                system.debug('attach file name ' + bAttach.filename);
                
                Attachment attach = new Attachment();
                
                //attach.Body = Blob.valueOf(bAttach.body.toString());
                String b64Data = EncodingUtil.base64Encode(bAttach.body);
                //Blob bab = bAttach.body;
                attach.Body = Blob.valueOf(b64Data);
                attach.Name = bAttach.filename;    // name of the attachement should be same a attached to email
                //attach.parentId = submitRecord.Id;
                attach.parentId = abcdRecId;
                listAttach.add(attach);        
            }
            system.debug('attach list size ' + listAttach.size());
            insert listAttach;
        }
    }
    
}

 

I would appreciate if someone assist me with the solution. Thanks in Advance-----

Best Answer chosen by Admin (Salesforce Developers) 
Sai Ram ASai Ram A

 

public class EmailParsingActivity {

public void attachToRecord(Messaging.InboundEmail.BinaryAttachment[] bAttachments, ID urRecID) {
List<Attachment> listAttach = new List<Attachment>();
if(bAttachments != null) {
for(Messaging.InboundEmail.BinaryAttachment bAttach : bAttachments)

 

//system.debug('attach file name ' + bAttach.filename);

Attachment attach = new Attachment();
attach.Body = bAttach.body;
attach.Name = bAttach.filename; // name of the attachement should be same a attached to email
attach.parentId = urRecID;
listAttach.add(attach);
}
system.debug('attach list size ' + listAttach.size());
insert listAttach;
}
}

}

 

 

All Answers

Integrator9Integrator9

Me too Facing the Same Issue , Have you got any Solution for this Issue, please let us know

 

Thanks in advance

Sai Ram ASai Ram A

 

public class EmailParsingActivity {

public void attachToRecord(Messaging.InboundEmail.BinaryAttachment[] bAttachments, ID urRecID) {
List<Attachment> listAttach = new List<Attachment>();
if(bAttachments != null) {
for(Messaging.InboundEmail.BinaryAttachment bAttach : bAttachments)

 

//system.debug('attach file name ' + bAttach.filename);

Attachment attach = new Attachment();
attach.Body = bAttach.body;
attach.Name = bAttach.filename; // name of the attachement should be same a attached to email
attach.parentId = urRecID;
listAttach.add(attach);
}
system.debug('attach list size ' + listAttach.size());
insert listAttach;
}
}

}

 

 

This was selected as the best answer