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
AmbigaRamAmbigaRam 

Mapping fields within in same object

Hi,

 

I need to copy the project name when the new case is created by email

 

For that I created new custom settings "CaseProject" with custom fields CaseEmail (field Email) It contains the values of ToAddress of  the email message.

 

Following are my trigger code, When I saved ,I get the complation Error:unexpected token: 'Map' at line 15 column 8

 

Please help me to solve this issue.

 

trigger UpdateMostRecentmessageOnCase on EmailMessage (after insert) {
    Case relatedCase;
    Contact relatedCaseContact;
   
    
    for (EmailMessage e_msg : trigger.new) {
        //Find the related case.
        relatedCase = [SELECT Id FROM Case WHERE Id = :e_msg.ParentId];
        Integer msgCount = [SELECT COUNT() FROM EmailMessage];
       If (relatedCase != null)
            {
        //If the case was found, updated the most recent comment.
       If(e_msg.ToAddress != null)
       {
        Map prjts = CaseProject__c.getAll();
        List mails = new List();
        mails.addAll(prjts.keySet());
        for (String key : mails) {
            CaseProject__c cToP = prjts.get(key);
            if(cToP.ProjectEmail__c.equals(e_msg.ToAddress)) {
           relatedCase.Project_Name__c = cTop.Name; 
            }
        }  
       
            
            relatedCase.Most_Recent_Email_Message__c = e_msg.textBody;
            relatedCase.CaseEmail__c = e_msg.ToAddress;
            update relatedCase;
            
           
            
            
            }
            }
            
         
    }
}

 Thanks and Regards.,

Ambiga

sfdcfoxsfdcfox
Your Map requires two parameters: the type of the key, and the type of the value. In the case of a custom setting, it looks like this:

Map<String, CustomSetting__c>

So, in your case, it would look like:

Map<String, CaseProject__c> prjts = CaseProject__c.getAll();
AmbigaRamAmbigaRam

Hi ,

 

I tried that one. But again expecting the error in  lists.

 

Will you please tell me is it possible mapping of two field within the same object.

 

If it is, please write the sample code.

 

Thanks & Regards.

Ambiga

sfdcfoxsfdcfox
Lists also require a parameter. For example, a list of accounts would be written as List<Account>.
AmbigaRamAmbigaRam

Hi ,

 

Thanks for your reply and finally I resolved my problem

 

 

Regards,

Ambiga