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
Internal PartnerInternal Partner 

Problems with formula using Case Owner: User and Case Owner: Queue in a field predefined value

Hi all,

We are using Queues in order to assign Cases first to Queues and when someone is a queue member he/she can own the case.
You have the possibility to send emails on Cases.

So, now we have the requirement to set the From field of an Email to the Queue email address of the Case Owner per default:

User-added image

For example, let's say we have a Case and the Case Owner is Test User X. This user belongs to the Queue USA. So, when the case owner wants to send an email the From field should be set to the Queue Email Address of the Queue he/she belongs, e.g. TestEmail2Case@queue-email.com.

The same way if the Case Owner is a Queue, the From field on an Email should be set to the Queue email address per default.

I was trying to implement this on the Email Action on the Case object creating predefined values there.

In order to set the Queue email address for the From field I built this formula:
 
IF(OR(NOT(ISBLANK(Case.Owner:User.Id)),NOT(ISBLANK(Case.Owner:Queue.Id))) , Case.Owner:Queue.QueueEmail, 'None')
This is unfortunately not working, maybe something in the logic is wrong.

If I hard code using this formula for example, it works but only using Queue as a condition:
 
CASE(Case.Owner:Queue.QueueName, 
"USA","TestEmail2Case@queue-email.com",  
"Canada","TestEmail2Case2@queue-email.com",
"None")

I am using the email addresses verified in the Email-To-Case settings for the Queues.
Does anybody have an idea how to adjust the formula according to the described requirement? (hopefully understandable)
 
Andrew GAndrew G
Hi
Your logic needs some refinement.   If we think about the Owner field, which can be a User or a Queue, we need to work out first if its a User or Queue, before we start trying to handle some of the related record details.
So in Code we could try like this:
for (Case newCase: Trigger.new) {
    if(newCase.Owner.Type=='User'){
        System.debug('Owner is a User') 
        // do your user processing
    else {
        System.debug('Owner is a Queue') 
        // do your queue processing
    }
}
or we can test by the Object prefix:
for (Case newCase : Trigger.new) {
    String objPrefix = newCase .ownerId;
    if(objPrefix .startsWith('005') == TRUE){
        System.debug('Owner is a User') 
        // do your user processing
    else {
        System.debug('Owner is a Queue') 
        // do your queue processing
    }
}
If we are talking Formula, something like below should work:
 
IF( LEFT(OwnerId,3) = '00G', 
    Case.Owner:Queue.QueueEmail,
    Case.Owner:User.Email)

HTH

Andrew​​​​​​​


 
Andrew GAndrew G
Hi

Seems i'm seeing your emails but not the posts. 
To answer the question:

'00G' is the prefix for queues/groups - all queue records will have a prefix of '00G'.  Same as all accounts start with '001', Contacts - '003'  '005' is a User etc

So basically the code is saying, in the Owner field, if the first 3 characters of the Id of the record start with '00G', we have a group/queue as opposed to a User in the Owner field.  Since we have detected a group/queue, I can use the Queue.QueueEmail to populate the email address.  If the Owner is not a group/queue, then it is a user, and we use the User.Email value to populate the field.

So if we are chasing the email address associated with the queue to operate as the send from address, the above should work.  Membership of multiple queues/groups has not affect as the Owner field has only one entry - either a Queue or a User - therefore there is only one email address to send from.

I would suggest in a sandbox that you create a formula field with the suggested formula and change the Owner field to see the effect that the change will have.  

Regards
Andrew