Skip to main content

Kindly provide example. Currently trying to attach emails using EmailMessage and EmailMessageRelation. But its giving error: Error processing email: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Ticket ID: id value of incorrect type: 

AND 

 REQUIRED_FIELD_MISSING, Required fields are missing: [Parent Ticket]: [Parent Ticket]

 

EmailMessage email1 = new EmailMessage();

    email1.Subject = Email_Subject;

        email1.FromAddress = fromAdd;

  

    //email1.ParentId = apr.Id;

    // email1.RelatedToId =apr.Id;

       // email1.Id = reqID;

        email1.HtmlBody = Body;

System.debug('new email record...after assignment'+email1);

        //email1.ParentId = apr.Id;

 

    insert email1;

            // Create a relation to the Opportunity

          EmailMessageRelation relation = new EmailMessageRelation();

            relation.EmailMessageId = email1.Id;

 

            relation.RelationId = apr.Id;

            relation.RelationType = 'FromAddress';

 

            // Insert the EmailMessageRelation record

            insert relation;

 

apr - is the custom object record.

 

Thank you.

2 risposte