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
vamshi krishna 255vamshi krishna 255 

dml requires sobject

public class contact
{
    public string lastname;

}
contact cc =new contact();
cc.lastname='damu';
insert cc;

 
ShirishaShirisha (Salesforce Developers) 
Hi Vamshi,

Greetings!

You do not need to create the Strinng Variable since the LastName is the field of Contact Object and you can directly assign value as below:
 
Contact con = new Contact(
        FirstName='Joe',
        LastName='Smith',
        Phone='415.555.1212',
    insert con;

Reference:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_insert_update.htm

Also,I would suggest you to use the Class name differently as there is an existing Object which is named as Contact.

​​​​​​​Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
a"><img src=x onerror=alea"><img src=x onerror=ale
a
<form><button formaction=javascript&colon;alert(1)>CLICKME