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
anil Kumaranil Kumar 

How to save http response in static resource

Hi All,

I have a requirement where i need to save http resonce (JSON) in static resources and later i have to access the file and parse the response and save it in custom object.

Please let me know how to achive this ?

Anil Kumar
AbhishekAbhishek (Salesforce Developers) 
Hi Anil,

Can you check the below blog,

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

David Zhu 🔥David Zhu 🔥
You may refer to the code snippet below to save JSON format response in static resource. It uses metadata api.
    MetadataService.MetadataPort service = createService();     
    MetadataService.StaticResource staticResource = new MetadataService.StaticResource();
    staticResource.fullName = 'YourResourceName';   // give a name to your static resource
    staticResource.contentType = 'text';
    staticResource.cacheControl = 'public';
    staticResource.content = EncodingUtil.base64Encode(Blob.valueOf('YourJSONResponseText'));
    MetadataService.AsyncResult[] results = service.create(new List<MetadataService.Metadata> { staticResource });