I like to create a report folder via Apex trigger/class is it possible.

Thanks in advance


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.

  • I like to create it via enterprise wsdl by generating the apex class from created wsdl file. Is this possible. – Mangoski Apr 22 '14 at 15:50
  • @Rajeshkumar The enterprise WSDL is very large and getting any of Salesforce's own WSDLs callable through Apex is pretty difficult. The one that has had most effort applied AFAIK is the Metadata one. See e.g. github.com/financialforcedev/apex-mdapi. Though I think you would probably have to do some additional work on it to get the folder part to work. – Keith C Apr 22 '14 at 15:59
  • can i get any reference to proceed further with folder creation using the link you provided above. – Mangoski Apr 22 '14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.