• nitin sharma 397
  • NEWBIE
  • 25 Points
  • Member since 2020

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 7
    Replies
How do I send an email notification to a user?

I need to send it 25 days after creation of a record. This should be simple but I don't know if there is some standard function for this or I have to use formula?
Hi All,

I need a bit of help in understanding the concept of transactions as far as batch apex is concerned....
 
From trigger,one can run only 5 transactions of  batch apex.what does it mean?When and how do we execute those 5 transactions From Trigger.Any explanation with an example will be highly appreciated.

In Trigger ,one can process 200 records,Right? So If I  call batch class from trigger which I know is not a good idea..Despite knowing that if i call batch apex class and pass list of 200 sobject Id's,Will it start one transaction of  batch apex class and then another set of 200 records will execute this class again and third time also it sends 200 records which starts another transaction so on and so forth.


So in case if I upload 1200 records using data loader for account object and account object has a trigger which call's a batchable class.Does it means that trigger will call batchable class 6 times to pass the records or pass all 1200 records to the batchable class in one go.
Secondly:- What happens to the governor limits when a batchable class runs.Everytime a batchable class is called from a trigger and exceuted ,Does it  reset it's governor limits,Is that right? 

Guys,please clear my doubt as soon as possible.

 
.


 
Salesfore Experts, 
 
I am working on a requirement where I need to trigger email with all attachments on a ticket when owner gets changed. The below mentioned code works as expected in Sandbox and I get 87% code coverage but when we try to deploy in production the code coverage is reduced to 25% which I am unable to figure out what is causing it. 
And We are getting error is 
"  ystem.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, zGLOBAL_New_Owner_Notifi_Trigger: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times) Class.zGLOBAL_New_Owner_Notifi_Attachment.emailSender: line 9, column 1 Trigger.z  "
 
public class zGLOBAL_New_Owner_Notifi_Attachment  {

public static void emailSender(Map<Id,Case> oldMap, Map<Id,Case> newMap) {
    // this is a list for storing email for settoAddress 
    List<String>toAddress =new List<String>();
    // this is a list for storing email for setccAddress 
    List<String>CCAddress =new List<String>();
    
    List<contact> lstcont=[select id ,Email,name,phone from contact];
    Map<String,String> mapContact=new Map<String,String>();
    list<String> ccAddresslst=new List<String>();
    map<string,String> mapuser=new map<string,string>();    
    Set<Id> accIds=new Set<Id>();
    Set<Id> recId=new Set<Id>();
   
    String ownerName=''; 
    String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
    
    //for getting user email and store in map where user id is key and email is value
    for(User u:[select id, name, Email from user]) 
    {
        mapuser.put(u.id,u.email);
    }
    
    //for getting Contact name  and store in map where  id is key and name is value
    for(contact con:lstcont)
    {
        mapContact.put(con.id,con.name);
    }
    
    
    //Change Trigger.new with udtCases
    for(Id key : oldMap.keySet())
    {
        case oldcase=oldMap.get(key);
       case cs=newMap.get(key);
        
        if(cs.zGloblal_Total_attachments__c>=1 && cs.APEX_Owner_notifications_Attachments__c==true)
        {
            //Changed Trigger.oldMap
          
            

            if(oldcase.OwnerId!=cs.OwnerId)
            {
               if(string.valueOf(cs.OwnerId).startsWith('005'))
                {
                    toAddress.add(mapuser.get(cs.OwnerId));  
                    ownerName=Getqueuemember.getOwnername(cs.OwnerId);
                }
                
                else{ 
                    CCAddress=Getqueuemember.getEmailfromuser(cs.OwnerId);
                    ownerName=Getqueuemember.getqueueOwnername(cs.OwnerId);
                }
                
                
                List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
                List<Attachment> attlist=[select Name, Body, BodyLength from Attachment where ParentId = :cs.id ];
                for (Attachment a :attlist){
                    
                    Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                    
                    efa.setFileName(a.Name);
                    efa.setBody(a.Body);
                    fileAttachments.add(efa);
                }
                
                
                String Subject='Ticket #'+cs.CaseNumber+' has been assigned to  '+' '+ownerName;
                
                
                
                try{
                    
                   
                    Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
                    
                    
                    
                    semail.setSubject(Subject); 
                    semail.setSenderDisplayName('Salesforce Support'); 
                    semail.setTargetObjectId(cs.ContactId);
                    //semail.setTemplateId(et.id);
                    semail.setCcAddresses(CCAddress);
                    semail.setToAddresses(toAddress); 
                    
                    semail.setHtmlBody('***THIS IS A SYSTEM GENERATED MESSAGE! DO NOT REPLY!***<br/><br/>Please be advised that the following SalesForce ticket has been assigned to  '+ownerName+'<br/><br/> Ticket #:'+cs.CaseNumber+
                                       '<br/>Subject:'+cs.subject+'<br/><br/>Contact Name: '+mapContact.get(cs.Contactid)+'<br/>Contact Phone (primary): '+Getqueuemember.r(cs.ContactPhone)+'<br/>Contact Mobile (primary): '+Getqueuemember.r(cs.ContactMobile)+
                                       '<br/> Contact Email:'+Getqueuemember.r(cs.ContactEmail)+'<br/><br/>Category: '+Getqueuemember.r(cs.Ticket_Category__c)+Getqueuemember.r(cs.Service_Category__c)+Getqueuemember.r(cs.Ticket_Category2__c)+               
                                       '<br/>Type: '+Getqueuemember.r(cs.Ticket_Type__c)+Getqueuemember.r(cs.Service_Type__c)+Getqueuemember.r(cs.Ticket_Type2__c)+                           
                                       '<br/>Item: '+Getqueuemember.r(cs.Ticket_Item__c)+Getqueuemember.r(cs.Service_Item__c)+Getqueuemember.r(cs.Ticket_Item2__c)+                   
                                       '<br/>Ticket Source: '+Getqueuemember.r(cs.Case_Source__c)+'<br/><br/><br/>Building: '+Getqueuemember.r(cs.building__c)+'<br/>Room: '+Getqueuemember.r(cs.Room_Number__c)+'<br/>Area Description: '+Getqueuemember.r(cs.Area_description__c)+
                                       '<br/><br/><br/>Click the appropriate link below to view the ticket directly:<br/><br/>Partner Portal Users: <a href='+baseUrl+'/'+cs.id+'>'+baseUrl+'/'+cs.id+'</a><br/>BlackbeltHelp (Community Users): <a href='+Getqueuemember.getcommunityurl(cs.AccountId)+cs.id+
                                       '>'+Getqueuemember.getcommunityurl(cs.AccountId)+cs.id+'</a><br/><br/>Description:'+cs.Description+'<br/><br/>Internal Notes: '+Getqueuemember.r(cs.Internal_Notes__c)); 
                    semail.setFileAttachments(fileAttachments);     
                    semail.setWhatId(cs.id);
                 Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail}); 
                    
                }
                catch(exception e)    
                {}
                
            }
        }
    }
}
}

And Test class is
@isTest
public class zGLOBAL_New_Owner_Notifi_AttachmentTest {
    @isTest
    public Static void emailTest()
    {
       // create test account
        Account acc = TestUtilityController.getAccount('MassBay');
        acc.APEX_Owner_notifications_Attachments__c=true;
        insert acc;
        
        // create test contact
        Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
        insert con;
        
        // fill utility
        UtilityController.fillUtilities();
        UtilityController.isUtility = false;
        
        trigger_control__c tc = new trigger_control__c();
        tc.name='test';
        tc.Enable_Owner_Notification_Trigger__c=true;
        insert tc;
        
        // Create test cases 
        List<Case> listCase = new List<Case>();
        
        if(UtilityController.caseRecordType.containsKey('MassBayCC_Ticket')){
            String recordTypeId = UtilityController.caseRecordType.get('MassBayCC_Ticket').Id;   
                 
             
            Case csanew = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
            csanew.status = 'Action - Automated Escalation';
            csanew.zGloblal_Total_attachments__c=2;
            csanew.Ticket_Category2__c = 'Blackboard Learn - LMS';
            csanew.Ticket_Type2__c = 'Faculty/Staff';
            csanew.Ticket_Item2__c='Tutorial';
            listCase.add(csanew);
            
    //Added additional code here
     System.test.startTest();

            insert listCase;


System.Test.stopTest();

            Getqueuemember.getcommunityurl(acc.id);
            Getqueuemember.getEmailfromuser('0050W0000061RWD');
            Getqueuemember.getOwnername('0050W0000061RWD');
            Getqueuemember.getqueueOwnername('00Gd00000027kH7');
            Getqueuemember.r(csanew.Ticket_Category2__c);
        
    }

}
    
   

}

​​​​​​​

 
How to Write a trigger that automatically create a contact when account is created?
How do I send an email notification to a user?

I need to send it 25 days after creation of a record. This should be simple but I don't know if there is some standard function for this or I have to use formula?
Hi, I am simply trying to add a note using the Notes object and relate it to a custom object with flow?
Hi, I have custom Status__c picklist field on Account. I have a need when account gets inactivated with value pick "Inactive" then all contacts related to the account should also get inactive (contact also have  picklist custom field Contact_Status__c with one of the value as "Active". Apparently, combination of PB and Flow is not working. I would like to tackle this with trigger.

*Also can this be reversble also if account her reactivated again then contacts gets active? 
  • February 14, 2020
  • Like
  • 0
Whenever I sent emails from flow builder using a text template it sends the plain text version. If I format it in the rich text, it will send the plain text version with all of the html markup. 

I have written a process builder that should create/ update child records when 1000s of parents records are updated from external system. However process builder seems to throw error for these records, examples are-

ERROR: We can't save this record because the PROCESSBUILDER process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: CaseTrigger: System.LimitException: Too many DML statements: 151. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 723127467-93191 (-1369958504)

ERROR: We can't save this record because the PROCESSBUILDER process failed. Give your Salesforce admin these details. This error occurred when the flow tried to update records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the PROCESS BUILDER process failed. Give your Salesforce admin these details. This error occurred when the flow tried to update records: REQUEST_RUNNING_TOO_LONG: Your request was running for too long, and has been stopped.. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 2146764366-2599833 (1255675226). You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 2146764366-2599835 (1022480718)

Please tell me how can I make process builder work for this scenario.

Thanks