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

trigger on task

hey guys,

since it is still not possible to trigger a workflow from email to task in salesforce, im trying to solve that with an apex trigger. im trying to change the custom field(newTask.Ergebnis_Aktivit_t__c) to my chosen value, if the subject starts with "E-Mail"
Im pretty new to apex and this created from what i found on the internet.

trigger emailergebnis on Task (before Insert) {

    /*Iterate over the newly created Tasks one by one*/
    for(Task newTask :{

        /*Check if the Task is being created as result of Email to Task*/
            !String.isBlank(newTask.Subject) &&
            newTask.Ergebnis_Aktivit_t__c = 'Email / SMS / Whatsapp';
it does not change anything. would appreciate if somebody can guide me to the error
Raj VakatiRaj Vakati
Looks like its salesforce issues .. i tested your code couple of instances .. Once instance it is not working but other instance it working as expected 

trigger TaskT on Task (before insert) {
    for(Task tNew :{
        /*Check if the Task is being created as result of Email to Task*/
        if(!String.isBlank(tNew.Subject) && tNew.Subject.toLowerCase().startsWith('e-mail:')){
             tNew.Ergebnis_Aktivit_t__c = 'Email / SMS / Whatsapp';
            // newTask.addError('NOWWWW');