• Abdul Subahani BS 8
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
global class inboundEmail implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        contact con =[SELECT Id,AccountId,Email,FirstName,LastName,Name FROM Contact WHERE email= :email.fromaddress LIMIT 1];
        
        if(con != null){
            case cs=new case();
            cs.Status='New';
            cs.Origin='Phone';
            cs.contactid=con.id;
            cs.subject=email.subject;
            cs.description=email.plaintextbody;
            
            try{
                insert cs;
                result.success=True;
            }catch(DMLException e){
                system.debug('Following error occured'+e);
                result.success=false;
            }
        }else{
/*in place of a print message I would like to create a new contact or a case?*/
             System.debug('contact dosent exist');  
        }
        
        return result;
    }
    
}

 
global class inboundEmail implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        contact con =[SELECT Id,AccountId,Email,FirstName,LastName,Name FROM Contact WHERE email= :email.fromaddress LIMIT 1];
        
        if(con != null){
            case cs=new case();
            cs.Status='New';
            cs.Origin='Phone';
            cs.contactid=con.id;
            cs.subject=email.subject;
            cs.description=email.plaintextbody;
            
            try{
                insert cs;
                result.success=True;
            }catch(DMLException e){
                system.debug('Following error occured'+e);
                result.success=false;
            }
        }else{
/*in place of a print message I would like to create a new contact or a case?*/
             System.debug('contact dosent exist');  
        }
        
        return result;
    }
    
}