I've created a trigger that calls the metadata api (class created from metadata api wsdl) for updating the picklist value in a sobject. Now with this working fine i need to deploy it for which the code coverage is required.

I wrote the below piece of code to test:

            static testmethod void UpdateSalesOwnerPicklist_Tr(){
            user usr =  new user();
            usr.LastName = 'Phil';
            usr.Alias = 'Sphil';
            usr.Email = 'non@none.co.uk';
            usr.Username = 'spencer.phil@capita.co.uk';
            usr.CommunityNickname = 'Phil';
            usr.TimeZoneSidKey = 'Europe/London';
            usr.LocaleSidKey = 'en_GB';
            usr.EmailEncodingKey = 'ISO-8859-1';
            usr.ProfileId = '00e2400000103uxAAA';
            usr.LanguageLocaleKey = 'en_US';
            //insert user
            insert usr;

but for the error Methods defined as TestMethod do not support Web service callouts

Following this i did refer the link:


but quite confused on how to approach the test class? any help on this please?


Here is the logical layman explanation:during test run actual webservice call can't be made and hence you define a mock callout class.

During test run your test class actually looks for your mock class response and continues test execution.

So define a mock class as explained in the link you found and return a fake response which will be same as actual webservice response.

| improve this answer | |
  • Thanks Mohit. so as you pointed i did understand that its not possible which had me look into the help doc from SF. But there raises couple of questions...Do i need to recreate the entire class as in the help doc? or shud i make adjustments to my api generated class? – Prabhu Sethupathy Nov 19 '15 at 13:40
  • the wsdl given as example is not seen anywhere in the console....so i assume it is just for example...so with that context adjustments to my generated api class seems very complex as the type definitions needs to be amended – Prabhu Sethupathy Nov 19 '15 at 13:42
  • You might be using only specific method of WSDL for that class ..Try adding test for only that – Mohith Shrivastava Nov 19 '15 at 13:45
  • Also you will recreate a mock class and use that in test.setmock – Mohith Shrivastava Nov 19 '15 at 13:46

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.