• Avinash.Babu
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi Community,
I have a custom object called Daily Assessment and this object has a master detail relation ship with Entitlements. Every day a Daily Assessment record has to be under the entitlements (Meaning that daily assessment report was generated for that Entitlement).I wanted a Scheduled class which will fire an email if there are no child records created on the entitlement on any given day.

The following is the code i have:

global class DailyAssessmentSchedulable implements Schedulable {
    
    public static String emailAddress = 'avinash.babu@groupelite.com';
    
    global void execute(SchedulableContext ctx) {
        List<Entitlement> entitlementList = new List<Entitlement>();
        List<Entitlement> notificationList = new List<Entitlement>();
        List<Daily_Assessment__c> dailyAssessmentList = new List<Daily_Assessment__c>();
        MAP<Id, Entitlement> entitlementMap = new Map<Id, Entitlement>([SELECT Id,
                                  Name, 
                                  (SELECT Id, 
                                          CreatedDate, 
                                          Entitlement_Name__c 
                                   FROM Daily_Assessments__r 
                                   WHERE CreatedDate = TODAY) 
                                  FROM Entitlement
                                  WHERE Name LIKE '%MSO%']);
        
        entitlementList = entitlementMap.values();
        for(Entitlement ent : entitlementList){
            //logic to decide which user has not submitted and 
            //add it to a list and send email using sendEmail() method
            dailyAssessmentList = new List<Daily_Assessment__c>();
            dailyAssessmentList = ent.Daily_Assessments__r;
            if(dailyAssessmentList.isEmpty()){
               notificationList.add(ent);
            }
        }
        
        sendEmail(notificationList);
    }
    
    //send email method
    private void sendEmail(List<Entitlement> notificationList){
        if(notificationList != null){
            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.toAddresses = new String[] {emailAddress};
            message.subject = 'Entitlement Daily Assessment reports update';
            message.plainTextBody = 'Dear chris, Daily Assessments for the following entitlements were not submitted today: ';
            for(Entitlement ent : notificationList){
               message.plainTextBody += ent.Name + ', ';    
            }            
            Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
            Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
            
            if (results[0].success) {
                System.debug('The email was sent successfully.');
            } else {
                System.debug('The email failed to send: ' + results[0].errors[0].message);
            }
        }
    }
    
}

The issue with this code is whenever i run this class it is looking for the entitlement's child record created date and if all the entitlements are having new child date on that calendar day then an empty Email is being sent with the foloowing text (Daily Assessments for the following entitlements were not submitted today). How can i add a condition so that i will not fire the email if the Entitlements have child records on a calendar day.

How can I solve this Issue? Can anyone help me this Issue.

Thank you.
Hello Community,

Some Of our users who have modify data permissions got an email saying that the we have one or more certificates expiring.

The following is the exact message they received.

Subject: Sandbox: SFDC Expiring Certificate Notification

You have one or more certificates in your Salesforce org *************** that will expire soon. Review the list below and visit Certificate and Key Management from Setup to make an update.

- SelfSignedCert_24Feb2016_152454, Self-Signed, expires on 2/24/2017. Warning: This certificate will expire in 30 day(s).

I went through different community posts and followed the steps in those by looking in to Certificate and key management in our sandbox and I see that there is no certificates created at least. Also, we don't have any single sign on enabled.

So i don't understand why we got this email regarding Sandbox (Not Production).

Can anyone help me o this issue?

Thanks.
 Hi,

I have a requirement with my client wherein we are required to generate a unique random number on creation of a record in the system.

To cater to which I have written a below line of code-

integer max=6;
string password=EncodingUtil.ConvertToHex(crypto.generateAesKey(128)).substring(1,max);
recordToUpdate.put('Seller_Code__c'),'S'+password);

this code works fine.But not sure whether this code will generate a unique random number everytime.Can anyone help me with this?

In case if this code does not generates a unique random number how can I handle through same code?