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

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

Ankit Gupta@ DeveloperAnkit Gupta@ Developer

Use the below code snippet as reference:

list<string>strlst=new list<string>{'a','b'};
string body1='';
for(string s:strlst)
Blob b = Blob.valueOf(body1);
Attachment attach1= new Attachment();
attach1.ParentId = parentId;
attach1.Name = 'Test Attachment for Parent';
attach1.Body = b;

insert attach1;

Annkit gupta
Abhik SahaAbhik Saha
How can I create that content of the attachment as a zip file? I think they way code is working here it would be a text file. now, if I also want it to be zipped, how can I do that?
hd ss 6hd ss 6
The porpose  of the web page/elegance  could be to be used as Landing  web page in place of the house page when chatter consumer is logging  and I need to force the person to just accept a few terms and circumstance of sewing (