• Virender Singh 29
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
I am writing my first trigger. It involves two objects:
  1. Opportunity (Standard Object)
  2. Holding Object (Custom Object) 
What is supposed to happen is the following:

A name is chosen from a picklist field on the opportunity. Upon save the trigger should go look at the Holding Object object and find that name and pull the email address from that Persons record on the custom object.

Here is screenshot of what I have so far including the error.

User-added image

The actual code is below (in case the above is hard to read):

trigger Opportunity_Adelphic_AE_Email_Trigger on Opportunity (after update, before insert, before update, before delete) {
Opportunity [] opp = trigger.new;
                //Fill in the Adelphic AE email fields based on the person selected from the drop down list. 
                    for(integer i=0;i <opp.size();i++){

                        Set<string> Person = new Set<string>();
                        Person.add(trigger.new[i]. Adelphic_AE__c);

                        
                        if(Person.Size() > 0){
                            map<string, string> DM = new map<string, string>();
                                Holding_Object__c [] DMM = [select Persons_Name__c, Email_Address__c from Holding_Object    __c where Persons_Name__c in: Person ];
                                    for(Holding_Object__c lzip: DMM){
                                        DM.put(lzip.Persons_Name__c, lzip.Email_Address__c);
                                    }
                                    for(Holding_Object__c h: DMM){
                                        trigger.new[i]. Adelphic_AE_Email__c = DM.get(trigger.new[i]. Adelphic_AE__c);
           }
}

The error I am receiving is: "Compile Error: unexpected syntax: 'mismatched input '<EOF>' expecting RCURLY' at line 20 column 1.

Any feedback and guidance would be appreciated.
When a Case is created by Email-to-Case, we find that the CreatedById is set to a special UserId which seems to refer to the Automated Case User 'System' which is configured at Customize > Cases > Support Settings.

I've found that in Apex Trigger code, running for the 'before insert' event on the Case object, this User can be identified by statements such as:

    if (UserInfo.getName() == 'System')
    if (UserInfo.getUserName().startsWith('automatedcase@'))
    if (UserInfo.getUserType() == 'AutomatedProcess')
    
However, I think that if changes are later made to the Case > Support Settings so that the Automated Case User is an actual User then the above code will no longer give the same result.

Is there, therefore, a reliable way to identify during trigger execution that the Case is being created by Email-to-Case rather than by some other method (manual entry, clone, visualforce, etc.)?

Thanks in advance for any suggestions.

Regards
John Lewis