+ 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 ?

Thanks,
Anil Kumar
AbhishekAbhishek (Salesforce Developers) 
Hi Anil,

Can you check the below blog,

https://salesforce.stackexchange.com/questions/217599/how-to-save-response-in-static-resource-to-call-that-response-in-web-service-tes

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

Thanks.
 
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 });