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
Jack Rose 1Jack Rose 1 

Uploaded Documents Name Set by Picklist Value

Hi All, 

I have a VF page that is used by customers to upload documents to us, which create and attach themselves to a case. 
The name of the attachment is currently being set by the controller. 

I want the document name to include the value from a picklist on the page (Type_of_Document__c) however the the name is currently showing the field API name. 

Any thoughts on how to fix this?
insert objcase;
   
       System.debug('@@@@@objcase' +objcase);
        System.debug('@@@@@fileBody'+fileBody);     

        myAttachment  = new Attachment();

              Integer i=0;

              myAttachment.clear();

              myAttachment.Body = fileBody; 

              myAttachment.Name = 'Type_of_Document__c'+objcase.id+'.jpeg' ; 

              myAttachment.ParentId = objcase.id;             

              insert myAttachment;

 
Best Answer chosen by Jack Rose 1
Harshit Garg 6Harshit Garg 6
HI Jack,
 
insert objcase;
   
       System.debug('@@@@@objcase' +objcase);
        System.debug('@@@@@fileBody'+fileBody);     

        myAttachment  = new Attachment();

              Integer i=0;

              myAttachment.clear();

              myAttachment.Body = fileBody; 

              myAttachment.Name = objcase. Type_of_Document__c+'.jpeg' ; 

              myAttachment.ParentId = objcase.id;             

              insert myAttachment;

Please use above code. If helpfull for you please choose my ans as the best ans.

Thanks,
Harshit Garg

All Answers

Harshit Garg 6Harshit Garg 6
HI Jack,
 
insert objcase;
   
       System.debug('@@@@@objcase' +objcase);
        System.debug('@@@@@fileBody'+fileBody);     

        myAttachment  = new Attachment();

              Integer i=0;

              myAttachment.clear();

              myAttachment.Body = fileBody; 

              myAttachment.Name = objcase. Type_of_Document__c+'.jpeg' ; 

              myAttachment.ParentId = objcase.id;             

              insert myAttachment;

Please use above code. If helpfull for you please choose my ans as the best ans.

Thanks,
Harshit Garg
This was selected as the best answer
Harshit Garg 6Harshit Garg 6
Same define that field as the Origin in the code.