• Ella
  • NEWBIE
  • 20 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I have a scheduled flow to run daily : 

1. A get element that will take all my contacts under specific criteria : 
User-added image2. I loop through all the contacts found: 
User-added image

3. I assign the IDs of the loop into a variable.
User-added image
4. I have an APEX class to send an email and the last action is to send the email to the contacts. 
public class SendIMRMonthlyEmails {
    
    @InvocableMethod
    public static void invokeapex(list<Project_Contacts__c>ProjectContacts){
        List<Id> contactIds = new List<Id>();
        List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
        EmailTemplate et=[Select id from EmailTemplate where name = :System.Label.Sent_IMR_Monthly_Email_Project_Contacts limit 1];
        
        for(Project_Contacts__c obj : ProjectContacts){
            if(obj.Project_Deliverables__c=TRUE){
                contactIds.add(obj.Id);
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTargetObjectId(obj.Project_Contact__c);
                mail.setSenderDisplayName('IMR Monthly Emails');
                mail.setTemplateId(et.id);
                mail.setSaveAsActivity(FALSE);
                mail.setWhatId(obj.Id);
                mail.setBccAddresses(new List<String> {System.Label.Sent_IMR_Monthly_Email_BCC_Email});
                emailList.add(mail);      
        }   
    }
        Messaging.sendEmail(emailList);
    }  
}


Still, when I ran the flow I receive an error: "
An Apex error occurred: System.LimitException: Too many Email Invocations: 11" which leads me to the idea that I did something wrong to the flow or to the apex class. 

User-added image
  • November 16, 2021
  • Like
  • 0
I have an apex class that displays a toast message . I don't know why but my toast message is displayed only when I refresh the page , not when the record is open. How can I achieve this?

<aura:component  Controller="GetAccount" implements="lightning:availableForFlowScreens,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="record" type="Map" default="{}" />
    <aura:attribute name="disabled" type="Boolean" default="true" />
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <force:recordData targetFields="{!v.record}"
        recordId="{!v.recordId}"
        recordUpdated="{!c.recordLoaded}"
        fields="Has_Code_Red_Cases__c,Has_Critical_Situation_Request_Cases__c"/>
    
</aura:component>

Controller:

({
    doInit : function(component,event,helper){
        var action = component.get("c.getAccountList");
        var currentId = component.get("v.recordId");
        action.setParams({ "currentId":currentId });
        
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var allValues = response.getReturnValue();
                if(allValues[0].Has_Code_Red_Cases__c == true){
                    
                    var record = component.get("v.record");
                    var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                        title : 'This Account Has An SRC Code Red Case!',
                        message: record.Has_Code_Red_Cases__c,
                        duration:' 5000',
                        key: 'info_alt',
                        type: 'warning',
                        mode: 'sticky'
                    });
                    toastEvent.fire();   
          
                }
             if(allValues[0].Has_Critical_Situation_Request_Cases__c == true){
                    
                    var record = component.get("v.record");
                    var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                        title : 'This Account Has A Critical Situation Request Case!',
                        message: record.Has_Critical_Situation_Request_Cases__c,
                        duration:' 5000',
                        key: 'info_alt',
                        type: 'warning',
                        mode: 'sticky'
                    });
                    toastEvent.fire();   
          
                }   
                
            }
        });
        $A.enqueueAction(action);
    },
    
    recordLoaded: function(component, event, helper) {
        component.set("v.disabled", false);
    }
 })

 
  • June 18, 2021
  • Like
  • 0
Hello,
I have the following apex class and I need to write a test apex class for it. I started writing it but the code coverage is 0% . I am new into this and I don't know how to write it - can somebody help me ? 

APEX Class : 
public class GetAccount {
    
    @AuraEnabled
    public static List<Account> getAccountList(String currentId){
        List<Account> lstAcc = new List<Account>();  
        lstAcc = [Select id,Has_Code_Red_Cases__c,Has_Critical_Situation_Request_Cases__c from Account where id =: currentId];
        return lstAcc;
    }
}
TEST APEX CLASS:

@isTest 
public class GetAccountTest 
{
static testMethod void testMethod1() 
            {
                           Account acc = new Account();
                           acc.Name = 'Test Account';
                           insert acc;         
            }
}
  • April 22, 2021
  • Like
  • 0
I have a scheduled flow to run daily : 

1. A get element that will take all my contacts under specific criteria : 
User-added image2. I loop through all the contacts found: 
User-added image

3. I assign the IDs of the loop into a variable.
User-added image
4. I have an APEX class to send an email and the last action is to send the email to the contacts. 
public class SendIMRMonthlyEmails {
    
    @InvocableMethod
    public static void invokeapex(list<Project_Contacts__c>ProjectContacts){
        List<Id> contactIds = new List<Id>();
        List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
        EmailTemplate et=[Select id from EmailTemplate where name = :System.Label.Sent_IMR_Monthly_Email_Project_Contacts limit 1];
        
        for(Project_Contacts__c obj : ProjectContacts){
            if(obj.Project_Deliverables__c=TRUE){
                contactIds.add(obj.Id);
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTargetObjectId(obj.Project_Contact__c);
                mail.setSenderDisplayName('IMR Monthly Emails');
                mail.setTemplateId(et.id);
                mail.setSaveAsActivity(FALSE);
                mail.setWhatId(obj.Id);
                mail.setBccAddresses(new List<String> {System.Label.Sent_IMR_Monthly_Email_BCC_Email});
                emailList.add(mail);      
        }   
    }
        Messaging.sendEmail(emailList);
    }  
}


Still, when I ran the flow I receive an error: "
An Apex error occurred: System.LimitException: Too many Email Invocations: 11" which leads me to the idea that I did something wrong to the flow or to the apex class. 

User-added image
  • November 16, 2021
  • Like
  • 0
I have an apex class that displays a toast message . I don't know why but my toast message is displayed only when I refresh the page , not when the record is open. How can I achieve this?

<aura:component  Controller="GetAccount" implements="lightning:availableForFlowScreens,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes">
    <aura:attribute name="record" type="Map" default="{}" />
    <aura:attribute name="disabled" type="Boolean" default="true" />
    
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    <force:recordData targetFields="{!v.record}"
        recordId="{!v.recordId}"
        recordUpdated="{!c.recordLoaded}"
        fields="Has_Code_Red_Cases__c,Has_Critical_Situation_Request_Cases__c"/>
    
</aura:component>

Controller:

({
    doInit : function(component,event,helper){
        var action = component.get("c.getAccountList");
        var currentId = component.get("v.recordId");
        action.setParams({ "currentId":currentId });
        
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var allValues = response.getReturnValue();
                if(allValues[0].Has_Code_Red_Cases__c == true){
                    
                    var record = component.get("v.record");
                    var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                        title : 'This Account Has An SRC Code Red Case!',
                        message: record.Has_Code_Red_Cases__c,
                        duration:' 5000',
                        key: 'info_alt',
                        type: 'warning',
                        mode: 'sticky'
                    });
                    toastEvent.fire();   
          
                }
             if(allValues[0].Has_Critical_Situation_Request_Cases__c == true){
                    
                    var record = component.get("v.record");
                    var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                        title : 'This Account Has A Critical Situation Request Case!',
                        message: record.Has_Critical_Situation_Request_Cases__c,
                        duration:' 5000',
                        key: 'info_alt',
                        type: 'warning',
                        mode: 'sticky'
                    });
                    toastEvent.fire();   
          
                }   
                
            }
        });
        $A.enqueueAction(action);
    },
    
    recordLoaded: function(component, event, helper) {
        component.set("v.disabled", false);
    }
 })

 
  • June 18, 2021
  • Like
  • 0