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
VAHBVAHB 

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;
                else
                    c.Closed_By__c = c.OwnerId;
            }
            else {}
        }
}

ibtesamibtesam

Hello,

 

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!