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
bob17bob17 

Get content of a static resource from withing a trigger

Anyone know how I could get the contents of a static resource, a text file, from within a trigger.  You can't create a PageReference and then use the getContent().toString() method - that's not allowed from within a trigger.

 

Thanks in advance for any assistance

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Hey

 

You should be able to select the contents as you would with other object types e.g.

 

 List<StaticResource> sr = [Select body, name from StaticResource where Name = 'xx']; 

 

Cheers,

Wess 

All Answers

WesNolte__cWesNolte__c

Hey

 

You should be able to select the contents as you would with other object types e.g.

 

 List<StaticResource> sr = [Select body, name from StaticResource where Name = 'xx']; 

 

Cheers,

Wess 

This was selected as the best answer
bob17bob17

Wess, you rock! 

 

Shame on me for not at least looking at the data model to see if Static Resources were an exposed object.

 

Thanks again,

 

Bob

Ispita_NavatarIspita_Navatar


Static resources are query-able via Apex, so you can extract the contents of a static resource after query and looping through the query results.


Please find attached the sample query:-
Select s.Id, s.Body From StaticResource s



bos beanbos bean

I have a text file in static resources.  when I ran this query, I found the body is either encoded or encrypted.  Any idea how it is stored in the databse?  Thanks

bos beanbos bean
I found it, it's base64 encoded.