• Lara Ballwieser
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello everbody,

i have to write a trigger that insert a case.  if the email in this case is not in a contact object the trigger create a contact. I tried this:

trigger CaseTrigger on Case (after insert) {        
    for(Case ca:trigger.new){      
            
        Contact[] caseWithEmail = [SELECT Id,Email FROM Contact WHERE Email = :ca.SuppliedEmail];
            
        if(caseWithEmail.isEmpty()){
            
        Contact newContact = new Contact(FirstName = ca.First_Name__c, LastName = ca.Last_Name__c, Phone = ca.SuppliedPhone, Email = ca.SuppliedEmail,
                                        MailingStreet = ca.MailingStreet__c, MailingCity = ca.MailingCity__c, MailingPostalCode = ca.MailingPostalCode__c,
                                        MailingState = ca.MailingState__c);
     insert newContact;
  }
    } 
}

I think a piece is absence but I don't know what it is.
Can somebody help me to find it?

Thank you!
Hello everbody,

i have to write a trigger that insert a case.  if the email in this case is not in a contact object the trigger create a contact. I tried this:

trigger CaseTrigger on Case (after insert) {        
    for(Case ca:trigger.new){      
            
        Contact[] caseWithEmail = [SELECT Id,Email FROM Contact WHERE Email = :ca.SuppliedEmail];
            
        if(caseWithEmail.isEmpty()){
            
        Contact newContact = new Contact(FirstName = ca.First_Name__c, LastName = ca.Last_Name__c, Phone = ca.SuppliedPhone, Email = ca.SuppliedEmail,
                                        MailingStreet = ca.MailingStreet__c, MailingCity = ca.MailingCity__c, MailingPostalCode = ca.MailingPostalCode__c,
                                        MailingState = ca.MailingState__c);
     insert newContact;
  }
    } 
}

I think a piece is absence but I don't know what it is.
Can somebody help me to find it?

Thank you!