Skip to main content
Prashanthkumar Annarapu a posé une question dans #Apex
public class relatedcaserecords 

{

    public static void createcaserecord()

    {

        case cs = new case();

        cs.Status='New';

        cs.Priority='High';

        cs.Type='Mechanical';

        insert cs;

        //creating related contact record

        if(cs.id!=null)

        {

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

            Contact con = new Contact();

                con.FirstName='NAYANATHARA';

                con.LastName='Contact record';

                 con.Title='Sales manager';

                 con.Phone='7780282373';

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

                 con.HomePhone='99005544433';

                 con.MailingCity='Hyderabad';

                 con.MailingState='Telangana';

                 con.MailingCountry='India';

            con.case id=cs.id;

            insert con;

            if(con.id!=null)

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

        }

    }

}

        }

    }

}

error:

it shows invalid type con.case

then how can we write the code
1 réponse
  1. 11 mars 2022, 06:47
    Hi Prashanth,

    Do you have Case field on the Contact object. If so check the API name of the field.

    con.case id=cs.id;  is not the correct API name of the field. There won't be any spaces in the API Name.

    If this solution helps, Please mark it as best answer.

    Thanks,

     
0/9000