You need to sign in to do that
Don't have an account?

Create Attachment body in apex
Hello Helper
I wowuld like to create an attchment in an apex code
I have a List<String> variable n my apex and I want somehow to save the strings in a file and attach it to a custom object
I know the attachment object and I know I can link this object with another custom object
what I do not know is how to add my data to the attachment object
I sew the field Body of the Attachment object but I do not know how to pass my string list data to the body
any advice is appreciated
Best Regards
Csaba
I wowuld like to create an attchment in an apex code
I have a List<String> variable n my apex and I want somehow to save the strings in a file and attach it to a custom object
I know the attachment object and I know I can link this object with another custom object
what I do not know is how to add my data to the attachment object
I sew the field Body of the Attachment object but I do not know how to pass my string list data to the body
any advice is appreciated
Best Regards
Csaba
Use the below code snippet as reference:
list<string>strlst=new list<string>{'a','b'};
string body1='';
for(string s:strlst)
{
body1=body1+''+s;
}
Blob b = Blob.valueOf(body1);
Attachment attach1= new Attachment();
attach1.ParentId = parentId;
attach1.Name = 'Test Attachment for Parent';
attach1.Body = b;
insert attach1;
Thanks
Annkit gupta