0

I've got some code and I've gotten some help fixing some errors in it yesterday. it worked but only on the first email and would only create one Parent Opp per email address.

I reworked it with some different code. However, I'm getting an error on line 34 - Unexpected Token 'insert'.

I don't know if I need to completely start over and right a code that will just create the parent opp object no matter what on an email and then add some parameters or what.


  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){

    // Create an InboundEmailResult object for returning the result of the 
    // Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

    String myPlainText= '';

    // Add the email plain text into the local variable 
    myPlainText = email.plainTextBody;

    // New Task object to be created
    Parent_Opportunity__C[] newParentopp = new Parent_Opportunity__C[0];

    // Try to look up any contacts based on the email from address
    // If there is more than one contact with the same email address,
    // an exception will be thrown and the catch statement will be called.
    try {
      Contact vCon = [SELECT Id, Name, Email
        FROM Contact
        WHERE Email = :email.fromAddress
        LIMIT 1];

      // Add a new Task to the contact record we just found above.
      newParentopp.add(new Parent_Opportunity__C(Description__C =  myPlainText,
           Priority__C = '1',                                      
           Subject__C = email.subject,


     // Insert the new Task 
     insert newParentopp;  

     System.debug('New Parent opportunity__C Record: ' + newParentopp );   
    }
    // If an exception occurs when the query accesses 
    // the contact record, a QueryException is called.
    // The exception is written to the Apex debug log.
   catch (QueryException e) {
       System.debug('Query Issue: ' + e);
   }

   // Set the result to true. No need to send an email back to the user 
   // with an error message
   result.success = true;

   // Return the result for the Apex Email Service
   return result;
  }
}```

1 Answer 1

1

you didnot close the newParentOpp addition.

newParentopp.add(new Parent_Opportunity__C(Description__C =  myPlainText,
           Priority__C = '1',                                      
           Subject__C = email.subject);

and then try 😊

3
  • missing extra right paren
    – cropredy
    Commented Dec 6, 2019 at 18:28
  • I tried that, now i'm getting a Missing ) and ; error. this is where I added the )
    – Kory Kent
    Commented Dec 6, 2019 at 20:03
  • I got it - no errors Needed the ) before the ;
    – Kory Kent
    Commented Dec 6, 2019 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .