• Cristian-Ovidiu Trif
  • NEWBIE
  • 30 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies

Hi, I have the following error: I'm not sure how to fix this

 When i ran the class i have one error which is this..
"SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, a3D9E000000Mdz0]—Send Email method looks for a contact while sending emails"

This is my code for sending email to users or queues

global class sendEmailBatchClass implements Database.Batchable < sobject > {
   
    global Database.QueryLocator start(Database.BatchableContext bc) {
        Date dt = date.today().addDays(1);
        return Database.getquerylocator([SELECT Id,OwnerId,Name,Owner.Email,
        (Select Id,OwnerId,Name,Owner.Email from SVMXC__Work_Orders__r where SIG_Due_Date__c =:dt and SVMXC__Order_Status__c NOT IN ('Closed','Completed')),
        (Select Id,OwnerId,Name,Owner.Email from Administrative_Tasks__r where SIG_Due_Date__c =:dt and SIG_Status__c Not IN ('Closed','Completed')) 
        From SVMXC__Service_Request__c  WHERE SVMXC__Status__c = 'Open' and SVMX_SIG_Due_Date__c  =: dt]);
    }
    
    global void execute(Database.BatchableContext bc, List <SVMXC__Service_Request__c> scope) {
       
        String userStringVal = '005';
        Map<Id,set<SVMXC__Service_Request__c>> srMap = new Map<Id, set<SVMXC__Service_Request__c>>();
        Map<Id, Set<SVMXC__Service_Order__c>> woMap = new Map<Id, Set<SVMXC__Service_order__c>>();
        Map<Id, Set<SIG_Administrative_Task__c>> atMap = new Map<Id, Set<SIG_Administrative_Task__c>>();
        Map<String, set<SVMXC__Service_Request__c>> userSRMap = new Map< String, set<SVMXC__Service_Request__c>>();
        Map<String, set<SVMXC__Service_Order__c>> userWoMap = new Map< String, set<SVMXC__Service_Order__c>>();
        Map<String, set<SIG_Administrative_Task__c>> userATMap = new Map< String, set<SIG_Administrative_Task__c>>();
       
        For(SVMXC__Service_Request__c srVal:scope){
            If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userSRMap.containsKey(srVal.Owner.Email)){
                userSRMap.put(srVal.Owner.Email,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   userSRMap.get(srVal.Owner.Email).add(srVal);
                }
            }
            else{
                if(!srMap.containsKey(srVal.OwnerId)){
                    srMap.put(srVal.OwnerId,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   srMap.get(srVal.OwnerId).add(srVal);
                }
            }
            
            For(SVMXC__Service_Order__c woVal :srVal.SVMXC__Work_Orders__r){
                If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userWoMap.containsKey(woVal.Owner.Email)){
                userWoMap.put(woVal.Owner.Email,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   userWoMap.get(woVal.Owner.Email).add(woVal);
                }
            }
            else{
                if(!woMap.containsKey(woVal.OwnerId)){
                    woMap.put(woVal.OwnerId,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   woMap.get(woVal.OwnerId).add(woVal);
                }
            }
            }
            
            For(SIG_Administrative_Task__c atVal :srVal.Administrative_Tasks__r){
                If(string.valueOf(atVal.OwnerId).startsWith(userStringVal)){
                if(!userATMap.containsKey(atVal.Owner.Email)){
                userATMap.put(atVal.Owner.Email,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   userATMap.get(atVal.Owner.Email).add(atVal);
                }
            }
            else{
                if(!atMap.containsKey(atVal.OwnerId)){
                    atMap.put(atVal.OwnerId,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   atMap.get(atVal.OwnerId).add(atVal);
                }
            }
            }
         }
         /***  Group Member Extracting ***/
         
         Set<Id> groupIds = new Set<Id>();
         groupIds.addAll(srMap.keyset());
         groupIds.addAll(woMap.keyset());
         groupIds.addAll(atMap.keyset());
         Map<Id,Set<user>> GpMap = new Map<Id,Set<User>>();
         
         Map<Id,User> userVal = new Map<Id,User>([SELECT User.Id, User.Email FROM User WHERE Id IN 
                                                (SELECT UserOrGroupId FROM GroupMember WHERE GroupId in : groupIds)]);
         
         
         For(GroupMember gm :[Select groupId, UserOrGroupId From GroupMember where groupId IN : groupIds]){
             if(GpMap.containsKey(gm.groupId)){
                 GpMap.get(gm.groupId).add(userVal.get(gm.UserOrGroupId));
             }else{
                 GpMap.put(gm.groupId,new set<User>{userVal.get(gm.UserOrGroupId)});
             }
         }
         // Extracting group member from Service Request
         
         If(!GpMap.isEmpty() && !srMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                if(!userSRMap.containsKey(usVal.Email)){
                userSRMap.put(usVal.Email,new set<SVMXC__Service_Request__c>(srMap.get(gVal)));
                }
                else
                {
                   userSRMap.get(usVal.Email).addAll(srMap.get(gVal));
                }
              }
         }
         }
        
         
          // Extracting group member from Work Order
          
         If(!GpMap.isEmpty() && !woMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                 if(!userWoMap.containsKey(usVal.Email)){
                 userWoMap.put(usVal.Email,new set<SVMXC__Service_Order__c>(woMap.get(gVal)));
                }
                else
                {
                   userWoMap.get(usVal.Email).addAll(woMap.get(gVal));
                }
              }
         }
         }
          // Extracting group member from Service Request
          
          If(!GpMap.isEmpty() && !atMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                  
                if(!userSRMap.containsKey(usVal.Email)){
                userATMap.put(usVal.Email,new set<SIG_Administrative_Task__c>(atMap.get(gVal)));
                }
                else
                {
                   userATMap.get(usVal.Email).addAll(atMap.get(gVal));
                }
              }
         }
         }
         
         // Sending Email for Service Request
          For(String userval1: userSRMap.keyset()){
           For(SVMXC__Service_Request__c srlistval: userSRMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                email.setTargetObjectId(srlistval.ownerId);
                email.setWhatId(srlistval.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          // Sending Email For Work Order
      
          For(String userval1: userWoMap.keyset()){
    
           For(SVMXC__Service_Order__c woListVal: userWoMap.get(userval1)){
         
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Work_Order_Escalation_Email'].id;
                email.setTargetObjectId(woListVal.ownerId);
                email.setWhatId(woListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          // Sending Email For Admin  Task
           For(String userval1: userATMap.keyset()){
           
           For(SIG_Administrative_Task__c adListVal: userATMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                email.setTargetObjectId(adListVal.ownerId);
                email.setWhatId(adListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          
          
    }
    
    global void finish(database.BatchableContext bc) {
        
    }
}

Hi, I want to change my column from 'Name' into 'Queue Name'. Is it possible?

User-added image

my VF code

 

<apex:page controller="Search_For_User">
<apex:form style="width: 500px" >
       <apex:pageBlock tabStyle="Account" >

              <apex:inputText value="{!keyword}"/>
              <apex:commandButton value="Search" action="{!searchUser}"/>

            <Apex:pageblockTable value="{!results}" var="r" style="width: 450px">
                  <apex:column value="{!r.FirstName}" />
                  <apex:column value="{!r.LastName}" />
                  <apex:column value="{!r.ProfileId}"/>
            </Apex:pageblockTable>
              <Apex:pageblockTable value="{!groupMembers}" var="g" style="width: 200px">
                  <apex:column value="{!g.Group.Name}"/>
           </Apex:pageblockTable>
            
       </apex:pageBlock>
</apex:form>
</apex:page>


Hi, I have this error on my code:

 

public class Search_For_User
{
    String keyword;

    List<user>results = new List<user>();
    
    public String getkeyword(){
    return keyword;
    }
   
    public List<user> getresults(){
    return results;
    }
    
    public void setkeyword(String input){
    keyword = input;
    }
    
    public PageReference searchUser(){
    results = (List<User>)[FIND :keyword IN NAME FIELDS RETURNING USER(FirstName, LastName, ProfileId)][0];
    return null;
 
    }

     System.debug(results);
 
    
}
Can someone help me please...
I created a multiselect picklist in jQuery and it looks like this:User-added imagenow the code for this is: 
<!DOCTYPE html>
<html lang="en-us">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>

<body>
<table>
<tr>
<td><select id="picklist1" multiple></select></td><td></td>
<td><select id="picklist2" multiple></select></td><td></td>
<td><select id="picklist3" multiple></select></td><td></td>
</tr>
</table>

<script>
(function($) {
	$.fn.multipicklist = function( options ) {
		var source = $(this[0]);
		var target = $(this[1]);
		if (options && options.length > 0) {
			$.each(options, function (i, item) {
				source.append($('<option>', {
    					value: i,
    					text: item
				}));
			});
		}

		var td = source.parent().next();
		td.append($('<p><a id="addTo' + target.attr('id') + '" href="#">&gt;</a></p>'));
		td.append($('<p><a id="subtractFrom' + target.attr('id') + '" href="#">&lt;</a></p>'));

		 $("#addTo" + target.attr('id')).click(function (e) { 
			target.append(source.find(":selected"));
			source.find(":selected").remove();
		});
		$("#subtractFrom" + target.attr('id')).click(function (e) { 
			source.append(target.find(":selected"));
			target.find(":selected").remove();
		});
	};

}(jQuery));

$("#picklist1, #picklist2").multipicklist(["option1","option2","option3","option4"]);
$("#picklist2, #picklist3").multipicklist();
</script>
</body>
</html>

And for this requirement I need the values from my picklist field instead of "option1","option2","option3","option4". Question is: How can get the values from my picklist field? I created a variable like this:

public Visit_Report__c record {get; set;}


then somewhere in my code, in my VF page i need to add this, I think:​​​​​​​

!record.Innovation_presented_to_customer__c
Any ideas how to implement this?
hi, i'm a newbie in development and i have this task to add one more box in the VF page. Now, we have only 2 boxes one is Available and the other one is Chosen.. but now the client wants one more box and it has to be like this: First box - Available, Second box - Presented, third box - Interested... and I don't know how to add the third box. I tried to look up in the code and I found the code which make this boxes...User-added imageUser-added imageI'm not sure how to add the third box in here... some suggestions, please?

Hi, I have the following error: I'm not sure how to fix this

 When i ran the class i have one error which is this..
"SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: [whatId, a3D9E000000Mdz0]—Send Email method looks for a contact while sending emails"

This is my code for sending email to users or queues

global class sendEmailBatchClass implements Database.Batchable < sobject > {
   
    global Database.QueryLocator start(Database.BatchableContext bc) {
        Date dt = date.today().addDays(1);
        return Database.getquerylocator([SELECT Id,OwnerId,Name,Owner.Email,
        (Select Id,OwnerId,Name,Owner.Email from SVMXC__Work_Orders__r where SIG_Due_Date__c =:dt and SVMXC__Order_Status__c NOT IN ('Closed','Completed')),
        (Select Id,OwnerId,Name,Owner.Email from Administrative_Tasks__r where SIG_Due_Date__c =:dt and SIG_Status__c Not IN ('Closed','Completed')) 
        From SVMXC__Service_Request__c  WHERE SVMXC__Status__c = 'Open' and SVMX_SIG_Due_Date__c  =: dt]);
    }
    
    global void execute(Database.BatchableContext bc, List <SVMXC__Service_Request__c> scope) {
       
        String userStringVal = '005';
        Map<Id,set<SVMXC__Service_Request__c>> srMap = new Map<Id, set<SVMXC__Service_Request__c>>();
        Map<Id, Set<SVMXC__Service_Order__c>> woMap = new Map<Id, Set<SVMXC__Service_order__c>>();
        Map<Id, Set<SIG_Administrative_Task__c>> atMap = new Map<Id, Set<SIG_Administrative_Task__c>>();
        Map<String, set<SVMXC__Service_Request__c>> userSRMap = new Map< String, set<SVMXC__Service_Request__c>>();
        Map<String, set<SVMXC__Service_Order__c>> userWoMap = new Map< String, set<SVMXC__Service_Order__c>>();
        Map<String, set<SIG_Administrative_Task__c>> userATMap = new Map< String, set<SIG_Administrative_Task__c>>();
       
        For(SVMXC__Service_Request__c srVal:scope){
            If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userSRMap.containsKey(srVal.Owner.Email)){
                userSRMap.put(srVal.Owner.Email,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   userSRMap.get(srVal.Owner.Email).add(srVal);
                }
            }
            else{
                if(!srMap.containsKey(srVal.OwnerId)){
                    srMap.put(srVal.OwnerId,new set<SVMXC__Service_Request__c>{srVal} );
                }else
                {
                   srMap.get(srVal.OwnerId).add(srVal);
                }
            }
            
            For(SVMXC__Service_Order__c woVal :srVal.SVMXC__Work_Orders__r){
                If(string.valueOf(srVal.OwnerId).startsWith(userStringVal)){
                if(!userWoMap.containsKey(woVal.Owner.Email)){
                userWoMap.put(woVal.Owner.Email,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   userWoMap.get(woVal.Owner.Email).add(woVal);
                }
            }
            else{
                if(!woMap.containsKey(woVal.OwnerId)){
                    woMap.put(woVal.OwnerId,new set<SVMXC__Service_Order__c>{woVal} );
                }else
                {
                   woMap.get(woVal.OwnerId).add(woVal);
                }
            }
            }
            
            For(SIG_Administrative_Task__c atVal :srVal.Administrative_Tasks__r){
                If(string.valueOf(atVal.OwnerId).startsWith(userStringVal)){
                if(!userATMap.containsKey(atVal.Owner.Email)){
                userATMap.put(atVal.Owner.Email,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   userATMap.get(atVal.Owner.Email).add(atVal);
                }
            }
            else{
                if(!atMap.containsKey(atVal.OwnerId)){
                    atMap.put(atVal.OwnerId,new set<SIG_Administrative_Task__c>{atVal} );
                }else
                {
                   atMap.get(atVal.OwnerId).add(atVal);
                }
            }
            }
         }
         /***  Group Member Extracting ***/
         
         Set<Id> groupIds = new Set<Id>();
         groupIds.addAll(srMap.keyset());
         groupIds.addAll(woMap.keyset());
         groupIds.addAll(atMap.keyset());
         Map<Id,Set<user>> GpMap = new Map<Id,Set<User>>();
         
         Map<Id,User> userVal = new Map<Id,User>([SELECT User.Id, User.Email FROM User WHERE Id IN 
                                                (SELECT UserOrGroupId FROM GroupMember WHERE GroupId in : groupIds)]);
         
         
         For(GroupMember gm :[Select groupId, UserOrGroupId From GroupMember where groupId IN : groupIds]){
             if(GpMap.containsKey(gm.groupId)){
                 GpMap.get(gm.groupId).add(userVal.get(gm.UserOrGroupId));
             }else{
                 GpMap.put(gm.groupId,new set<User>{userVal.get(gm.UserOrGroupId)});
             }
         }
         // Extracting group member from Service Request
         
         If(!GpMap.isEmpty() && !srMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                if(!userSRMap.containsKey(usVal.Email)){
                userSRMap.put(usVal.Email,new set<SVMXC__Service_Request__c>(srMap.get(gVal)));
                }
                else
                {
                   userSRMap.get(usVal.Email).addAll(srMap.get(gVal));
                }
              }
         }
         }
        
         
          // Extracting group member from Work Order
          
         If(!GpMap.isEmpty() && !woMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                 if(!userWoMap.containsKey(usVal.Email)){
                 userWoMap.put(usVal.Email,new set<SVMXC__Service_Order__c>(woMap.get(gVal)));
                }
                else
                {
                   userWoMap.get(usVal.Email).addAll(woMap.get(gVal));
                }
              }
         }
         }
          // Extracting group member from Service Request
          
          If(!GpMap.isEmpty() && !atMap.isEmpty()){
         For(Id gVal : GpMap.keyset()){
              For(User usVal : GpMap.get(gVal)){
                  
                if(!userSRMap.containsKey(usVal.Email)){
                userATMap.put(usVal.Email,new set<SIG_Administrative_Task__c>(atMap.get(gVal)));
                }
                else
                {
                   userATMap.get(usVal.Email).addAll(atMap.get(gVal));
                }
              }
         }
         }
         
         // Sending Email for Service Request
          For(String userval1: userSRMap.keyset()){
           For(SVMXC__Service_Request__c srlistval: userSRMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                email.setTargetObjectId(srlistval.ownerId);
                email.setWhatId(srlistval.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          // Sending Email For Work Order
      
          For(String userval1: userWoMap.keyset()){
    
           For(SVMXC__Service_Order__c woListVal: userWoMap.get(userval1)){
         
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Work_Order_Escalation_Email'].id;
                email.setTargetObjectId(woListVal.ownerId);
                email.setWhatId(woListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          // Sending Email For Admin  Task
           For(String userval1: userATMap.keyset()){
           
           For(SIG_Administrative_Task__c adListVal: userATMap.get(userval1)){
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                Id templateId =  [select id, name from EmailTemplate where developername = 'SIG_Service_Request_Escalation_Email'].id;
                email.setTargetObjectId(adListVal.ownerId);
                email.setWhatId(adListVal.Id);
                email.setTemplateId(templateId);
                email.setSaveAsActivity(false);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
          }
          
          
          
    }
    
    global void finish(database.BatchableContext bc) {
        
    }
}

Hi, I want to change my column from 'Name' into 'Queue Name'. Is it possible?

User-added image

my VF code

 

<apex:page controller="Search_For_User">
<apex:form style="width: 500px" >
       <apex:pageBlock tabStyle="Account" >

              <apex:inputText value="{!keyword}"/>
              <apex:commandButton value="Search" action="{!searchUser}"/>

            <Apex:pageblockTable value="{!results}" var="r" style="width: 450px">
                  <apex:column value="{!r.FirstName}" />
                  <apex:column value="{!r.LastName}" />
                  <apex:column value="{!r.ProfileId}"/>
            </Apex:pageblockTable>
              <Apex:pageblockTable value="{!groupMembers}" var="g" style="width: 200px">
                  <apex:column value="{!g.Group.Name}"/>
           </Apex:pageblockTable>
            
       </apex:pageBlock>
</apex:form>
</apex:page>
hi, i'm a newbie in development and i have this task to add one more box in the VF page. Now, we have only 2 boxes one is Available and the other one is Chosen.. but now the client wants one more box and it has to be like this: First box - Available, Second box - Presented, third box - Interested... and I don't know how to add the third box. I tried to look up in the code and I found the code which make this boxes...User-added imageUser-added imageI'm not sure how to add the third box in here... some suggestions, please?