+ Start a Discussion

Error on Apex code

Hey I am a complete beginner in this, I am sure I am making a stupid mistake but I wanted to set a field in Case Object based on two other fields. I am attempted to run it in Developer COnside and getting error: line 1, column 0: required (...)+ loop did not match anything at input 'trigger'


It fills in the value of the Closed By when a case is closed. It sets it to Sent To if it is not null, if not a case is always created by someone so it sets it to that value


trigger closedByTest on Case (before update) {    
        for (Case c : Trigger.new){
            Case oldcase = Trigger.oldMap.get(c.ID);

            if (c.ClosedDate != oldcase.ClosedDate){
                if (c.Sent_To__c != null)
                    c.Closed_By__c = c.Sent_To__c;
                    c.Closed_By__c = c.OwnerId;
            else {}




as you mentioned you tried it in developer console.

trigger cannot directly be executed in developer console. it is for executing some logic.


try pasting your code in trigger and do some testing!