0
public class TaskOneOpty {
List<opportunity> opp1 = [select id,amount, StageName from opportunity];
List<opportunity> opp2 = new List<opportunity>();
   for (opportunity OP:opp1)
    {
        if (OP.StageName == 'Closed Won')
            {
               OP.amount=OP.account.AnnualRevenue;
                opp2.add(OP); 
            }
    } 
update opp2;
}
5

You cannot write code in the body of a class. You must declare a method, constructor, property, or static initializer block.

I suggest reviewing the Classes section of the Apex Developer Guide.

|improve this answer|||||
4

You need to define a method which will execute this code. You should also always declare some sharing level on every class you ever write.

public with sharing class TaskOneOpty
{
    public static void doStuff()
    {
        List<opportunity> opp1 = [select id,amount, StageName from opportunity];
        List<opportunity> opp2 = new List<opportunity>();
        for (opportunity OP:opp1)
        {
            if (OP.StageName == 'Closed Won')
            {
                OP.amount=OP.account.AnnualRevenue;
                opp2.add(OP);
            }
        }
        update opp2;
    }
}
|improve this answer|||||

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.