4

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

Thanks in advance

1 Answer 1

1

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.

3
  • I like to create it via enterprise wsdl by generating the apex class from created wsdl file. Is this possible.
    – Mangoski
    Commented Apr 22, 2014 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
    Commented Apr 22, 2014 at 15:59
  • can i get any reference to proceed further with folder creation using the link you provided above.
    – Mangoski
    Commented Apr 22, 2014 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .