• Lovely Lopez
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
I'm trying to create a class that creates a task for an email inbound on a Contact level (but it would be really great if I can create it on Opportunity if you can help me figure it out). I'm currently testing this class on Contact and it isn't working. I'm not very well-versed with Apex. What am I doing wrong? Below is the Apex class I have.
global class CreateTaskEmail implements Messaging.InboundEmailHandler {
 
  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
    Task[] newTask = new Task[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, AccountId
        FROM Contact
        WHERE Email = :email.fromAddress
        LIMIT 1];
        
      Account a = [SELECT Id, OwnerId FROM Account WHERE Id = :vCon.AccountId];
      
      // Add a new Task to the contact record we just found above.
      newTask.add(new Task(Description =  myPlainText,
           OwnerId = a.OwnerId,
           Record_Type__c = 'Normal Task',
           Priority = 'Normal',
           Status = 'Completed',
           Subject = 'Email: ' + email.subject,
           Type = 'Email Inbound',
           ActivityDate = System.today(),
           WhoId =  vCon.Id));
     
     // Insert the new Task 
     insert newTask;    
     
     System.debug('New Task Object: ' + newTask );   
    }
    // 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;
  }
}
I hope you can help me. Thank you so much!
We have a checkbox called Web View and it automatically updates based on contact ID. I created a trigger that updates the checkbox in the account whenever there is a contact that has that checkbox checked. That works perfectly when the account is not a person account and has one or more contacts but it doesn't work when it comes to person account. I understand that a person account has an equivalent contact record for it. I would like the Web View checkbox in the account to be updated also whenever the Web View checkbox in the contact record of that person account is updated (I hope I'm making sense). What is the best way to do this? 
We have a checkbox called Web View and it automatically updates based on contact ID. I created a trigger that updates the checkbox in the account whenever there is a contact that has that checkbox checked. That works perfectly when the account is not a person account and has one or more contacts but it doesn't work when it comes to person account. I understand that a person account has an equivalent contact record for it. I would like the Web View checkbox in the account to be updated also whenever the Web View checkbox in the contact record of that person account is updated (I hope I'm making sense). What is the best way to do this?
I have a checkbox named Views in Contact and Account. I would like the checkbox in Account to be checked if one of the Contacts have that checkbox checked.  I know about the cross object formula but that only seem to work from Parent to Child object not the other way around. Is there any way to do this except for creating a trigger? If the trigger is only the solution, can you give me an idea what to do? I'm not very familiar with trigger yet. I would need help with this. Thank you!
I'm trying to create a class that creates a task for an email inbound on a Contact level (but it would be really great if I can create it on Opportunity if you can help me figure it out). I'm currently testing this class on Contact and it isn't working. I'm not very well-versed with Apex. What am I doing wrong? Below is the Apex class I have.
global class CreateTaskEmail implements Messaging.InboundEmailHandler {
 
  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
    Task[] newTask = new Task[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, AccountId
        FROM Contact
        WHERE Email = :email.fromAddress
        LIMIT 1];
        
      Account a = [SELECT Id, OwnerId FROM Account WHERE Id = :vCon.AccountId];
      
      // Add a new Task to the contact record we just found above.
      newTask.add(new Task(Description =  myPlainText,
           OwnerId = a.OwnerId,
           Record_Type__c = 'Normal Task',
           Priority = 'Normal',
           Status = 'Completed',
           Subject = 'Email: ' + email.subject,
           Type = 'Email Inbound',
           ActivityDate = System.today(),
           WhoId =  vCon.Id));
     
     // Insert the new Task 
     insert newTask;    
     
     System.debug('New Task Object: ' + newTask );   
    }
    // 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;
  }
}
I hope you can help me. Thank you so much!
We have a checkbox called Web View and it automatically updates based on contact ID. I created a trigger that updates the checkbox in the account whenever there is a contact that has that checkbox checked. That works perfectly when the account is not a person account and has one or more contacts but it doesn't work when it comes to person account. I understand that a person account has an equivalent contact record for it. I would like the Web View checkbox in the account to be updated also whenever the Web View checkbox in the contact record of that person account is updated (I hope I'm making sense). What is the best way to do this? 
We have a checkbox called Web View and it automatically updates based on contact ID. I created a trigger that updates the checkbox in the account whenever there is a contact that has that checkbox checked. That works perfectly when the account is not a person account and has one or more contacts but it doesn't work when it comes to person account. I understand that a person account has an equivalent contact record for it. I would like the Web View checkbox in the account to be updated also whenever the Web View checkbox in the contact record of that person account is updated (I hope I'm making sense). What is the best way to do this?
I have a checkbox named Views in Contact and Account. I would like the checkbox in Account to be checked if one of the Contacts have that checkbox checked.  I know about the cross object formula but that only seem to work from Parent to Child object not the other way around. Is there any way to do this except for creating a trigger? If the trigger is only the solution, can you give me an idea what to do? I'm not very familiar with trigger yet. I would need help with this. Thank you!