Some the requirements may come like the below,
Client need to create Email template folder
through visualforce page. Consider you have a custom Visualforce page and
one input text box and save button. When user give the name of email template
folder in vf then save it means the Email template folder need to be created.
Here is the base code to create an email template
folder,
- HTTP h = new HTTP();
- HTTPRequest req = new HTTPRequest();
- req.setMethod('POST');
- req.setHeader('Content-Type', 'text/xml');
- req.setHeader('SOAPAction', 'create');
- String b = '<?xml version="1.0" encoding="UTF-8"?>';
- b += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
- b += '<soapenv:Header>';
- b += '<ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">';
- b += '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>';
- b += '</ns1:SessionHeader>';
- b += '</soapenv:Header>';
- b += '<soapenv:Body>';
- b += '<create xmlns="http://soap.sforce.com/2006/04/metadata">';
- b += '<metadata xsi:type="EmailTemplateFolder" xmlns="http://soap.sforce.com/2006/04/metadata">';
- b += '<name>PersonalTemplates</name>'; //Email template Folder Label Name
- b += '<fullName>PersonalTemplates</fullName>'; //Email template Folder API Name
- b += '<accessType>Public</accessType>'; // Email Template Folder Visibility
- b += '<publicFolderAccess>ReadWrite</publicFolderAccess>'; //Email Template Access Level
- b += '</metadata>';
- b += '</create>';
- b += '</soapenv:Body>';
- b += '</soapenv:Envelope>';
- req.setBody(b);
- req.setCompressed(false);
- // Set this to org's endpoint and add it to the remote site settings.
- req.setEndpoint ('https://na15.salesforce.com/services/Soap/m/25.0'); // Change this domain based on your org. Like na17,ap1 something.
- HTTPResponse resp = h.send(req);
- System.debug(resp.getBody());
If you want to check this code working, Go to
Developer console, click Execute Anonymous window (CTRL+E), Paste the above
code and before execute this code Create remote site setting with your domain
address mentioned in the above Code.
Finally click execute, the go to your email folder
then you will see the folder called as “PersonalTemplates” in your org.
Change this base code according to your requirement...
Happy Coding…!
No comments:
Post a Comment