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
sathishsfdcsathishsfdc 

get the case owner id to match the User checkbox field and send email

Hi,
I am having 2 objects case and UserObject<No relationship between them>
In User object i have Checkbox field which will be checked to true/false by the corresponding user.

I m trying to check whether the CaseOwner Id of the particular case has User chexkbox field checked <in the User Object> and if so an email message will be sent.
trigger EmailMessageAfterUpdate on EmailMessage (after insert) {
    
      for(EmailMessage eMsg : Trigger.new) {
      
      User u = new User();
      
        List<Case> c = [SELECT id,ownerId, Description, caseNumber FROM Case WHERE Id = :eMsg.ParentId ];
        

}

Can someone let me know how to proceed?
Thanks

 
KaranrajKaranraj
Sathish - Case and User object has relationship, you can access the user field field in your soql query. You have mention Owner.FieldName__c
[SELECT id,ownerId,Description,caseNumber,Owner.Name FROM Case WHERE Id = :eMsg.ParentId];


 
sathishsfdcsathishsfdc
Hi karanraj,
thanks for the reply

i have a custom field called out_of_office_ c on the user object<checkbox field>

[SELECT id,ownerId,Description,caseNumber,Owner.Name FROM Case WHERE Id = :eMsg.ParentId and owner.out_of_office__c = true]

i am getting no such column on entity error.

However i am able to get the standard field  values like:

[select id,owner.isactive from case]
can u please advise
KaranrajKaranraj
It should work. Can you share your complete code here? It will be easy for us to assit better. Make sure that 'out_of_office__c' is the API of the field.
sathishsfdcsathishsfdc
Hi, I have created a custom field on User object:

Out_of_Office_Email_Address__c --Email field

Out_of_office__c -- checkbox field 

I am writing a trigger on email message which will  check whether the out_of_office checkbox is checked and will send an OOO reply through workflow

 
trigger EmailMessageAfterUpdate on EmailMessage (after insert) {
    
      for(EmailMessage eMsg : Trigger.new) {
      
      
       List<Case> c = [SELECT id,ownerId,Owner.Name ,Description, caseNumber FROM Case WHERE Id = :eMsg.ParentId and Owner.Out_Of_Office__c = true ];

My requirement is:

Fetch the Case Owner based on the parent ID of the email address.
Check if Out of Office flag is set for the user in the User Object.
Updates the Out_of_Office_Email_Address__c in User Object with the FromAddress in EmailMessageObject.

Thanks
sathish