function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
siva sai 22siva sai 22 

how to resolve "DML requires SObject or SObject list type: Opportunity" at line no 16

Hi friends i am getting error while i am inserting..here i am posting my code can you please reslove this
public class Opportunity {
          public string name{set;get;}
         public string closedate{set;get;}
         public string stagename{set;get;}
         public boolean isprivate{set;get;}
         public integer amount{set;get;}
         
 public  void create ()
   
    {
        Opportunity opp = new Opportunity();
        opp.Name= name;
        opp.CloseDate=closedate;
        opp.IsPrivate=isprivate;
        opp.Amount=amount;
16)        insert opp;
       
    }
}
thanks & Regards
krishna
Alain CabonAlain Cabon
Hi,

Class named: "Test" or any standard object (Account, Contact, Opportunity ..) fool the compiler.

public class Opportunity {

public class MyOpportunity {

Regards
siva sai 22siva sai 22
Hi, I forgot the naming convensions thatsy only it is comming tq
Alain CabonAlain Cabon
Hi, if the question is solved, you can close it (best practice here).
Thanks.
siva sai 22siva sai 22
Hi Alain ,
I need one more help "Variable does not exist: Phone"  and "Variable does not exist: LeadSource" please reslove me
public class MyLead {
    public integer annualRevenue{set;get;}
    public string phone {set;get;}
    public string lastName{set;get;}
    public string leadSource {set;get;}
    public string indus{set;get;}
    
    public void create()
    {
        Lead a =new Lead();
        a.Phone=phone;
        a.LeadSource = leadSource;
        
    }

}
 
Alain CabonAlain Cabon
Create a new apex class and copy/paste this:
public class MyLead {
    public integer annualRevenue{set;get;}
    public string phone {set;get;}
    public string lastName{set;get;}
    public string leadSource {set;get;}
    public string indus{set;get;}
    
    public void create()
    {
        Lead a =new Lead();
        a.Phone=phone;
        a.LeadSource = leadSource;        
    }  
}

The error you see is for another source code also opened like a Visualforce page.

The code above is correct (syntax) but that must be an apex class.

Regards