-
Notifications
You must be signed in to change notification settings - Fork 974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MD-API: Retrieve Email Alerts Metadata #21
Comments
Hi Andrew, I am able to get around the "Incompatibe issue" mentioned in the above post by extending the WorkflowAlert class as below
but now when I try to execute the code I get the below error:
I tried the below solutions but they did NOT solve the issue:
But neither of them seem to work. Could you please let me know of what is going wrong here? |
I am UK based, will take a few hours tonight see if I can help! :-) |
I see your attempting to use the new Spring'14 readMetadata operation, I assume your in a Spring'14 sandbox then? The polymorphic nature of the XML returned by the readMetadata method does make things a little tricky actually. I had a similar issue using readMetadata with Layouts for my blog here. http://andyinthecloud.com/2013/12/24/updating-layouts-in-apex/, take a look at the section "Working around xsi:type". Take a look at my version of readMetadata here, https://gist.github.com/afawcett/8108494#file-metadataservice-cls-L6648. This is prototype code ahead of Salesforce formally updating the platform to Spring'14, where i planned to more fully support this for other Metadata Types, not just Layout. I can have a go at getting this to work with WorkflowAlert if you want. |
Hi, GitHub appears to be having some problems, I'm hoping this email reaches Based on the work i did in my blog around the Spring'14 Metadata API i got // Read Workflow Alert Note that i noticed if you pass an invalid metadata full name in, it I'm not sure if this is a bug in the Metadata API or the Apex wrapper, I'll Please see attached files (see comment below for Gist). Thanks, Andy |
Ok GitHub is back, i've updated this Gist with a new MetadataService.cls (only for Spring'14 orgs, API v30). https://gist.github.com/afawcett/8108494 |
Hi Andrew,
But it gives the error:
I am trying to obtain the list of workflowalert names from the listmetadata() call and then read the metadata of each workflowalert by passing the WFA names in the string array. Also, I am trying to deeply understand the changes you have in your MetadataService.cls but I am new to this and still learning. So is it possible for you to let me know where I gotta start my learning and go to understand the MetadataAPI concepts in this depth? Sincerely appreciate your help and thanks once again for looking into this amid your busy schedule. |
No problem, can you confirm your using the MetadataService.cls i gave you in my previous response? |
We are struggling between our respective timezones i think here. But basically I've updated the MetadataService.readMetadata method from the standard generated one. This is because the XML deserialiser used by the platform does not support returning different data types, even though they all extend the same base Metadata type. So what i have done is allowed the caller of the method to pass in a hint to say which type of response will be expected and thus modify the parameter to the WebServiceCallout.invoke method to tell it the Response type to expect based on this. In order to make it work through a single method i have used an Apex Interface to make sure no matter what metadata response type is used its possible to obtain the list of metadata types. Since the response types all implement the interface (in due course i will make this change to all relevant metadata types, once Spring'14 is out in the wild). The error your getting still looks like a compilation / save error? So my conclusion is your still not using the version of the MetadataService.cls I gave you earlier? Is this because you don't have room in your org? If so, it might be worth creating a new Spring'14 pre-release org (different email address) so that you can at least use my copy and sample code to confirm for yourself it is working. |
Hi Andrew, Yes, I am based in Hong Kong now so time-zone is messy :( Btw, thanks again for thanks again for the details. Yes I am using your MetadataService.cls but only the sections relevant to the WorkflowAlert functionality since the whole class freezes my apex limit. Below is the abridged version of my MetadataService.cls merged with your changes namely - readmetadataservice, and the relevant classes.
Meanwhile, as per your advice, I am also creating new orgs and importing the whole of your MetadataService.cls into it and check if it that works there. |
Ok, if I get a chance i will try the one you have copied in above with the code your trying to execute, but on first glance it looks like you have the correct changes to your local copy. |
Thanks Andrew! I just tested it with your complete metadataservice.cls in new Orgs and found the error still occurs. Below is the error I see in my Dev Console.
So I believe if you just run my dev console code against your MetadataService.cls that you have in your Org, you will be able to see the issue. Below is my dev console code:
May I request you to kindly have a look into this. Thanks once again. |
Are you getting this error saving the code or running it? |
Ah forget the last question, your running via dev console, its likely a compile issue. I'll take a look for you with my copy of the MetadataService.cls file in my Spring'14 org. |
Yes Andrew, I am running from Anonymous Exec in Dev Console |
The MetadataService.cls saved without any issue. The error I get is when I run the other code in anonymous exec in dev console. |
This works for me...
Note you cast was incorrect, you need to cast to a list not a single item....
|
Thanks very much Andrew. I wouldn't have known that. It's working for me now but only for upto 10 records. If I try to run the dev console code for all the workflow alerts fetched fetched from ListMetadata() it gives the error:
Does this mean this webservice can handle only 10? If yes, is this limit set as a parameter MetadataService.cls? can this be modified or is there any work around you could suggest? The only option that I could think is to split the list of workflow alerts into batches of 10 and call the webservice for each batch until all the batches are processed. But I'm afraid it it will exceed the Callout limit. Can I please know your thoughts on this? However, thanks so much for bringing this to this extent. This wouldn't have been possible without your guidance. Thanks again! |
Yes this appears to be a documented limit. http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_readMetadata.htm
Yes splitting the calls up will get you further, you can make up to 10 outbound calls, since you have used 1 for the list, you have 9 remaining, so 90 possible to retrieve. Your other option to go further is to use Batch Apex, you could pass your list into a Batch Apex class (the start method supports returning a list, then when using Database.executeBatch set the scope size 100, the execute method will pass 100 at a time. chunk this up to 10 api calls per execute call). This way you can get through much more, but requires some Batch Apex programming. |
Thanks Andrew! All the fullnames I have are for WorkflowAlert and there are 250 of them. So splitting them also didn't help. So seems it's time for me to pick up batch apex :) Will surely try it and post you. Thanks very much Andrew!!! |
FYI. The main release in the repo now support Workflow reading. |
Dear Andrew,
Thanks again for stepping forward to help!
My use case is to retrieve the list of all email alerts in my org with their name, description, sender-address, recipients, & CC'ed recipients. For this I have come up with the below code which I execute from the anonymous exec in dev console.
But the execution stops with the error:
I believe it doesn't allow Metadata to be Typecast to WorkflowAlert. But I am not sure if the results can be achieved without doing that.
Can you please help letting me know where I am going wrong here?
Greatly appreciate your help! Many Thanks!
Note:
Since the class generated by the MetadataAPI wsdl exceeds my Apex Limit, I have cut it short to contain only what is required to achieve the required use case. Below is my short version of the MetadataService class used here for additional info, in case you like to have a look.
The text was updated successfully, but these errors were encountered: