I like to create a report folder via Apex trigger/class is it possible.
Thanks in advance
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
It is not possible if you try doing it directly e.g.:
insert new Folder(Name = 'MyFolderName', Type = 'Report');
because even as a System Administrator you will get the error:
DML not allowed on Folder
There is an undelivered idea about this Please Allow DML ops from Apex for MailMergeTemplate, BrandTemplate, and Folder.
But if this functionality is important enough, you can accomplish it by invoking the Metadata API from your Apex. (That would have to be asynchronous from a trigger via
@future.) A good starting point on how to do that is Introduction to calling the Metadata API from Apex.