Skip to content

Commit 98df69d

Browse files
committed
Update README.markdown
1 parent 62a0118 commit 98df69d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

README.markdown

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ While Salesforce offer on platform Apex developers a means to query some of this
3636

3737
Before you read on, stop by an [up vote this idea](https://success.salesforce.com/ideaView?id=08730000000l4TkAAI) to have a native Metadata API!
3838

39-
So what can we do in the meantime as Apex developers? Well it turns out that Apex is quite good at making outbound calls to Web Services and more recently REST base API's, all be it as always with a few governors to be aware. So why can Apex not call out to the Metadata Web Services API? After all, there is a WSDL for it and you have the ability as an Apex developer to import a WSDL into Apex and consume the code it generates to make the call, right? Well...
39+
So what can we do in the meantime as Apex developers? Well it turns out that Apex is quite good at making outbound calls to Web Services and more recently REST base API's, all be it as always with a few governors to be aware. So why can Apex not call out to the Metadata Web Services API? After all, there is a WSDL for it and you have the ability as an Apex developer to import a WSDL into Apex and consume the code it generates to make the call...
4040

4141
Examples
4242
--------
4343

4444
The following examples are a subset of those found in the [MetadataServiceExamples.cls](https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceExamples.cls).
4545

46+
```java
4647
public static void createObject()
4748
{
4849
MetadataService.MetadataPort service = createService();
@@ -111,6 +112,7 @@ The following examples are a subset of those found in the [MetadataServiceExampl
111112
service.SessionHeader.sessionId = UserInfo.getSessionId();
112113
return service;
113114
}
115+
```
114116

115117
You can view more examples [here](https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceExamples.cls). Thanks to [mohit-address](https://github.com/mohit-address) for submitting examples relating to updating picklist values.
116118

@@ -132,6 +134,7 @@ Metadata Batch Apex Demo
132134

133135
As described above you can poll the checkStatus operation for completion via either apex:actionPoller or Batch Apex. This example code shows how to create a number of Metadata components (custom object, fields and a page) from Apex without requiring Visualforce. You can read more about it [here](http://andyinthecloud.com/2013/05/06/scripting-the-apex-metadata-api-and-batch-apex-support/)
134136

137+
```java
135138
// Define Metadata item to create a Custom Object
136139
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
137140
customObject.fullName = objectName + '__c';
@@ -176,8 +179,9 @@ As described above you can poll the checkStatus operation for completion via eit
176179
new MetadataCreateJob.Item(customField2),
177180
new MetadataCreateJob.Item(apexPage, null, true) // Set wait to true, to process after field creation
178181
},
179-
new MetadataCreateJob.EmailNotificationMetadataAsyncCallback());
182+
new MetadataCreateJob.EmailNotificationMetadataAsyncCallback());
180183

184+
```
181185

182186
Metadata Retrieve Demo
183187
----------------------
@@ -199,6 +203,7 @@ To illustrate error handling, I've shown in the screen shot a deliberate failed
199203

200204
![Metadata Deploy Demo Screenshot](https://raw.github.com/financialforcedev/apex-mdapi/master/images/mddeploydemo.png)
201205

206+
```java
202207
public String getPackageXml()
203208
{
204209
return '<?xml version="1.0" encoding="UTF-8"?>' +
@@ -262,7 +267,9 @@ To illustrate error handling, I've shown in the screen shot a deliberate failed
262267
deployOptions.singlePackage = true;
263268
AsyncResult = service.deploy(ZipData, DeployOptions);
264269
return null;
265-
}
270+
}
271+
272+
```
266273

267274
**NOTE:** I am using Visualforce state (aka Viewstate) and Visualforce AJAX in the above two examples. This will limit the size of the files and zip file being exchanged. Use of JavaScript Remoting will give you increased flexibility in file size (docs state a response size of 15MB is supported). However this will mean storing state in a Custom Object, the slight additional complexity of this I wanted to avoid in these samples. As noted below I have recently (December 2012) enhanced the zip components in another repo, they are based on those in this repo, so are fairly simple to retro fit, take a look at the samples there first. Finally, keep in mind that you can also for most other Metadata Component types use the CRUD operations as shown above, which avoid any zip file handling.
268275

0 commit comments

Comments
 (0)