Skip to main content
public class contactsrecordshelper

{

    public static void createaccountrecord()

    {

        contact con = new contact();

        con.firstname='Latest';

        con.LastName='Bheemla';

        con.Email='latestbheemla@gmail.com';

        con.MailingCity='Hyderabad';

        con.MailingState='Telangana';

        con.MailingCountry='India';

        insert con;

        //created related case record

        if(con.id!=null)

        {

            system.debug('contact record created with id..:'+con.id);

            case cs = new case();

                cs.status = 'New';

                cs.Priority='High';

                cs.Type='Mechanical';

                cs.Reason='Performance';

            cs.conid=con.id;

            insert cs;

            if(cs.id!=null)

                system.debug('case record is created with id..:'+cs.id);

            

        }

    }

}

it shows the error 

cs.conid=con.id; variable does not exist
1 个回答
  1. 2022年3月12日 18:09
    Hey Prashanth,

    There is no field "conid" exist on case object. "ContactId" is the correct field as it is the lookup field with contact object. so your code will be like below 

    public class contactsrecordshelper

    {

    public static void createaccountrecord()

    {

    contact con = new contact();

    con.firstname='Latest';

    con.LastName='Bheemla';

    con.Email='latestbheemla@gmail.com';

    con.MailingCity='Hyderabad';

    con.MailingState='Telangana';

    con.MailingCountry='India';

    insert con;

    //created related case record

    if(con.id!=null)

    {

    system.debug('contact record created with id..:'+con.id);

    case cs = new case();

    cs.status = 'New';

    cs.Priority='High';

    cs.Type='Mechanical';

    cs.Reason='Performance';

    cs.contactId=con.id;

    insert cs;

    if(cs.id!=null)

    system.debug('case record is created with id..:'+cs.id);

    }

    }

    }

    Kindly mark it as best answer. 

     

    Thanks

0/9000