• rollo
  • NEWBIE
  • 5 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I have a wrapper class that is being called by a sfdc lightning component.  For some reason I am not able to access all the values of the class once it is passed.  They are seem to be set in the controller but the lightning controller does not access all of them.  Does anyone know what I am doing wrong.  My code is below.  I did remove some code for brevity.

Controller
@auraEnabled
         public static List<activityWrapper> getAllActivities() {
                     Id usrId = UserInfo.getUserId();
                     List<activityWrapper> allAct = new List<activityWrapper>();
                     dateTime startDate = system.now().addDays(-180);
                         dateTime endDate = system.now().addDays(180);
           List<Id> eventRelationIds = new List<Id>();
                     List<Id> contactIds = new List<Id>();
                      List<Id> accountIds = new List<Id>();
             List<eventRelation> evtRel = [select eventId, relationId, AccountId from eventRelation where event.Owner.id = :usrId and isInvitee = false and event.StartDateTime >= :startDate AND event.StartDateTime <= :endDate order by event.StartDateTime asc ];
             for(eventRelation ev: evtRel) {
               eventRelationIds.add(ev.eventId);
                             contactIds.add(ev.relationId);
                             accountIds.add(ev.AccountId);
             }
           List<Event> eventList = [SELECT Id, Activity_Type__c,recordType.name, whoId, EventWhoIds,  Subject, Short_Description__c, StartDateTime, Description, Activity_Status__c, Owner.Name,  Financial_Account__c, ActivityRelation__c, endDateTime, activityDate FROM event  WHERE Owner.id = :usrId and StartDateTime >= :startDate AND StartDateTime <= :endDate  order by startDateTime asc];
                     List<Contact> contList =[Select Id, Email, MailingCity, MailingStreet, MailingState, MailingCountry, MailingPostalCode, Phone, Account.Name, Name, AccountId from Contact where Id in :contactIds];
                     List<Contact> accContacts = [Select Id, Name, Phone, Email from Contact where AccountId in :accountIds];
                     for(event e: eventList){
                         for(contact c: contList){
                             if(e.whoId == c.Id){
                                string contName = c.Name;
                                  string accName = c.Account.Name;
                               string actStatus = e.Activity_Status__c;
                                  Id accId = c.AccountId;
                              string sub = e.Subject;
                                 string actType = e.Activity_Type__c;
                              Id contId = c.Id;
                                 string descr = e.Description;
                              string phone = c.Phone;
                                 string email = c.Email;
                               date actDate = e.ActivityDate;
                              datetime stDate = e.StartDateTime;
                                datetime eDate = e.EndDateTime;
                                id  eId = e.Id;
                                string actStreet = c.MailingStreet;
                                string  actCity = c.MailingCity;
                                string  actState = c.MailingState;
                                string  actZip = c.MailingPostalCode;
                                string  actCountry = c.MailingCountry;
                                string  actMultiPerson = '';
                                 if(e.EventWhoIds.size() > 1){
                                     actMultiPerson = ' +';
                             }
                                  allAct.add(new activityWrapper(contName, accName, actStatus, accId, sub, actType, contId, descr, phone, email,  actDate, stDate, eDate, eId, actStreet, actCity, actState, actZip, actCountry, actMultiPerson));
                             }
                         }
                     }
                     return allAct;
         }

                 public class activityWrapper{
                    @AuraEnabled public string actContact {get; set;}
                    @AuraEnabled public string actAcc {get; set;}
                    @AuraEnabled public string actStatus {get; set;}
                    @AuraEnabled public id actAccId {get; set;}
                    @AuraEnabled public string actSubject {get; set;}
                    @AuraEnabled public string actType {get; set;}
                    @AuraEnabled public id actContId {get; set;}
                    @AuraEnabled public string actDesc {get; set;}
                    @AuraEnabled public string actPhone {get; set;}
                    @AuraEnabled public string actEmail {get; set;}
                    @AuraEnabled public date actDate {get; set;}
                    @AuraEnabled public dateTime actStDate {get; set;}
                    @AuraEnabled public dateTime actEndDate {get; set;}
          @AuraEnabled public Id actId {get; set;}
                    @AuraEnabled public string actStreet {get; set;}
                    @AuraEnabled public string actCity {get; set;}
                    @AuraEnabled public string actState {get; set;}
                    @AuraEnabled public string actzip {get; set;}
                    @AuraEnabled public string actCountry {get; set;}
                    @AuraEnabled public string actMultiPerson {get; set;}
              public activityWrapper( string contName, string accName, string actStatus, Id accId, string sub, string actType, Id contId, string descr, string phone, string email,  date actDate, datetime stDate,datetime eDate,id  eId,string actStreet,string  actCity,string  actState, string  actZip,string  actCountry,string  actMultiPerson){
                                actContact = contName;
                                actAcc = accName;
                                actStatus =  actStatus;
                                system.debug('*** actStatus2 is '+actStatus);
                                actAccId = accId;
                                actSubject =  sub;
                                actType = actType;
                                actContId = contId;
                                actDesc = descr;
                                actPhone = phone;
                                actEmail = email;
                                actDate = actDate;
                                actStDate = stDate;
                                actEndDate = eDate;
                                actId = eId;
                                actStreet = actStreet;
                                actCity = actCity;
                                actState = actState;
                                actZip = actZip;
                                actCountry = actCountry;
                                actMultiPerson = actMultiPerson;
              }
          }

  init: function(component, event, helper) {

    var allEvents = [];

    var action = component.get('c.getAllActivities');

 
    action.setCallback(this, function(response) {
      var state = response.getState();
      if (state === "SUCCESS") {
        component.set('v.AllActivities', response.getReturnValue());

        allEvents = response.getReturnValue();


      }

    });
    $A.enqueueAction(action);
  },
 
Hi,

I have functionality to send 100 emails when Click on Notify button.

        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
            for(Contact con : contact)
            {
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setTargetObjectId(con.Id); 
                email.setWhatId(accountId); 
                email.setSaveAsActivity(true);
                mails.add(email);
            }
            if(mails.size()>0)
            {
                Messaging.SendEmailResult [] r = Messaging.sendEmail(mails);
            }    
            
    When emails are sent, it will create Task record in contact. I have trigger on Task Object to update field in account. When 100 task records are getting created, it is calling SOQL query in my below trigger 100 times. Please advice if my trigger is bulkified or is there any issue in Email sending code.
    
    List<account> accountId  = new List<ACcount();
    List<Task> triggerTask = Trigger.new != null ? Trigger.new : Trigger.old;
            for (Task task: triggerTask){
               String accountId = task.WhatId;
               if(task.Status =='Completed' && task.Isclosed==true && task.IsRecurrence == false && accountId !=null){
                   accountId.add(task.whatId);
               }
            } 
      
        
       if(accountId.size()>0){  
           List<accountId> accountList = [SELECT Id, (SELECT Id FROM Tasks where Status='Completed' and Isclosed=true and IsRecurrence = false) FROM Account WHERE Id IN :accountId];
          
           for(Account acc:accountList) {
               if(acc.Tasks != null) {
                     acc.Activities__c= acc.Tasks.size();
                   }
              }
            if(accountList.size()>0){
               update accountList;
            }
        }