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
Joaquin_teguiJoaquin_tegui 

Assigning a Task to a Queue

Hi All, 

I'm having an Issue when assigning a Task to a Queue. Right now if I crate a task in Annonymous apex with a queue ID everything works perfectly. But if I do it though a class of Inbound Email or a REST resource it fails. The error is that it does not recogni the queue ID.

Here is my code for the Email Service

global class inboundEmailTaskCreation implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
            Messaging.InboundEnvelope env){

        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

        String EmailBody= '';

        EmailBody = email.plainTextBody;

        Task newTask = new Task();

        try {
//Getting the queue Id
            Group gradoQueue = [SELECT ID from Group WHERE Type = 'Queue' AND DeveloperNAME = 'Grado' ];

//Creating the task
            newTask = new Task(Description = myPlainText,
                    Priority = 'Normal',
                    Subject = 'Correo Electrónico: ' + email.subject,
                    Status = 'Open',
                    ActivityDate = Date.today()
                    );



            insert newTask;

            System.debug('New Task Object: ' + newTask );
        }
        catch (QueryException e) {
            System.debug('Query Issue: ' + e);
        }

        result.success = true;

        return result;
    }
}

Any help will be useuful!

Thanks