function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sarah RobertsonSarah Robertson 

email message to address update

Hi I'm trying to edit this existing trigger, I want to add a condition so it runs when the email condition only contains certain text 

It's not liking this part of the apex :  
If(EmailMessage.ToAddress.contains=('SignedOrder')){

Here's the code I'm using, can anyone give me any pointers as to where I am going wrong ?

Thanks so much Sarah   :


trigger UpdateTo on EmailMessage (before insert) {


    //set<id> CaseIds = new set<Id>();
    map<Id,EmailMessage> MapEmailMessage = new map<Id,EmailMessage>();

    List<Case> newList = new List<Case>();

    for(EmailMessage e:trigger.new){
If(EmailMessage.ToAddress.contains=('SignedOrder')){



        MapEmailMessage.put(e.ParentId,e);

    }

    

    list<Case> lstC = [select Id,To__c from Case where id in:MapEmailMessage.keyset()];

    for(Case c:lstC){

        if(MapEmailMessage != null && MapEmailMessage.get(c.Id) != null )

            c.To__c = MapEmailMessage.get(c.Id).ToAddress;

            newList.add(c);

    }

    if(newList.size()>0)

    {

        update newList;

    }

}}
karthikeyan perumalkarthikeyan perumal
Hello, 

Use below code 
 
trigger UpdateTo on EmailMessage (before insert) {


    //set<id> CaseIds = new set<Id>();
    map<Id,EmailMessage> MapEmailMessage = new map<Id,EmailMessage>();

    List<Case> newList = new List<Case>();

    for(EmailMessage e:trigger.new){
If(e.ToAddress.contains('SignedOrder')){

    MapEmailMessage.put(e.ParentId,e);

    }

    

    list<Case> lstC = [select Id,To__c from Case where id in:MapEmailMessage.keyset()];

    for(Case c:lstC){

        if(MapEmailMessage != null && MapEmailMessage.get(c.Id) != null )

            c.To__c = MapEmailMessage.get(c.Id).ToAddress;

            newList.add(c);

    }

    if(newList.size()>0)

    {

        update newList;

    }

}}

Hope this will work

Thanks
karthik