1

The following is my trigger for Account,Based on which opportunity should be created

trigger CreateNewOpportunity on Account (after insert, after update) {
List<Opportunity> opportunities1 = new List<Opportunity>();
for(Account acct:Trigger.new){
    if(acct.industry == 'Electronics'){
    Opportunity nopportunity = new Opportunity();
    nopportunity.Name = acct.Name;
    nopportunity.AccountId = acct.Id;
    nopportunity.Amount = 10000;
    nopportunity.StageName = 'Proposal';
    nopportunity.CloseDate = System.today() + 30;

    opportunities1.add(nopportunity);
    }
}

if(opportunities1.isEmpty()== false){
   Database.upsert(opportunities1);
}}

And the test class for the above code is:

@isTest
public class CreateNewOpportunity{

    @isTest static void test_trigger(){
        Account acct = new account(Name = 'sha',industry == 'Electronics');
        insert acct;

      }
}

But I get the following error: Method defined as test method do not support web service..

Can you help me with this?

  • It seems that the source of this error is not the code that you have provided because your Trigger and Test class does not call a web service. You need to trace the exact origin of this error. Use debug log the find reason of error in code. This link may help you in using debug log – abdn Oct 23 '15 at 13:25
3

This is now due to what Salesforce has changed in one of the latest patches and the information is all here:

Methods defined as TestMethod do not support Web service callouts - Causing tests to fail instead of skipped - Began 10-21-2015

Basically, rather than allowing tests that cause a callout to be made to stop and be skipped, they allow the failure to happen.

If YOU have code that makes a callout when an Account is inserted, fix YOUR code to bypass the callout during tests or properly mock the callout.

If it is a Managed package that is making the callout when the account is inserted, I am afraid you will be unable to deploy any triggers related tot he account until either SF rolls back the patch or the vendor updates the package. You can still deploy classes and other triggers by running selected tests that have nothing to do with inserting an account and possibly nothing to do with your class. If your code coverage in your org is not healthy then you will just be stuck being unable to deploy at all.

| improve this answer | |
1

Check wheather callouts has been used in Account's trigger or any other classes.

| improve this answer | |
  • @Pri - Can you please explain why you accepted this answer as it is not really an answer and should be deleted – Eric Oct 23 '15 at 16:11
  • I also faced the same problem earlier @Eric9. I found out that there was a trigger calling callouts in Accont. Thats why I posted this answer – DOMINIC EDWARD Oct 24 '15 at 2:04
  • Mr @Priyalakshmi Can you please explain why you accepted this answer as it is not really an answer and should be deleted!! – Bforce Feb 22 '17 at 7:09

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.