• Travis Malle 9
  • NEWBIE
  • 60 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 12
    Replies
Hello Community,
 
I’m experiencing a strange issue that I’m not sure how to resolve. Any insights would be greatly appreciated…
 
I wrote some logic that is called by an after trigger on the Account object. The intent of my logic is to change the account owner of child accounts when the parent account is changed. This must only happen if a custom checkbox field is checked “Cascade_Ownership_Change__c” and if the trigger only contains one record (I don’t want this logic to run if there is a bulk change). Anyway, the logic works only when all of the child accounts are the same owner (not necessarily the same as the parent owner, just all the same person). If I try to perform an ownership change on a parent account where, for example, 1 child account out of 50 has a different owner. I get a Apex error stating the following: MasterTrigger_Account: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0016C000009UJLGQA4; first error: INVALID_FIELD, All accounts must have the same current owner and new owner.: [OwnerId] Class.Account_Utility.UpdateChildAccountOwnership: line 41, column 1 Trigger.MasterTrigger_Account: line 17, column 1
 
Here is what I’ve ruled out:
  • I do not have a validation rule preventing this update
  • Territory management does not have an effect on this logic
  • All applicable owners have a profile with read and edit permissions on all accounts
 
public void UpdateChildAccountOwnership(list<account> triggerNew, list<account> triggerOld){
        if(triggerNew.size() == 1 
           && triggerNew[0].Cascade_Ownership_Change__c == true
           && triggerNew[0].ownerId != triggerOld[0].ownerId
          )
        {
            id parentAcctId = triggerNew[0].id;
            id parentOwnerId = triggerNew[0].ownerId;
            list<account> childrenToUpdate= new list<account>();
            list<account> childAccts = [select id, parent_site__c, Name, ownerId from account where parent_site__c = :parentAcctId];
            
            for(account child : childAccts)
            {
                if(child.ownerId != null){
                    if(child.ownerId != parentOwnerId)
                    {
                        child.ownerId = parentOwnerId;
                        childrenToUpdate.add(child);
                    }                   
                }
            }
            
            update childrenToUpdate;
        }
    }
trigger MasterTrigger_Account on Account    (before insert, after insert, before update, after update, before delete, after delete) {
    /////* BEFORE TRIGGERS */////
    if (Trigger.isBefore)
    {
        if(Trigger.isInsert) {} 
        if(Trigger.isUpdate) {}
        if(Trigger.isDelete) {}
    }
    
    /////* AFTER TRIGGERS */////
    if (Trigger.IsAfter)
    {
        if(Trigger.isInsert) {} 
        if(Trigger.isUpdate) 
        {
            Account_Utility AcctUtil = new Account_Utility();
            AcctUtil.UpdateChildAccountOwnership(trigger.new, trigger.old);
            AcctUtil.CalculateEventScore(trigger.new, trigger.old);
            AcctUtil.CreateHistoryRecord(trigger.new, trigger.old);
        }
    } 
    if(Trigger.isDelete) {} 
}


 
Hello Community,

I’m developing a single Visualforce page that displays Visualforce charts in a tabbed layout and need some help with the most efficient way to get my chart data. Currently, I am populating the chart data via GetMethods in my controller, I understand this is a poor design as all methods will run every time the page reloads. Also, my methods are loaded with database queries that makes for long load times.
 
In an ideal state, I would like to initially load the page without calling any method in the controller, then when a button is clicked, call the appropriate method and populate the chart data.
 
If someone could give me some advice on the most efficient way to accomplish it would be greatly appreciated.
 
Thank you,

User-added image
Hello community,
 
I’m having a difficult time trying to access values from a list of generic sObject. Example:
 
Typically, I would do something like this:
list <account> acctlist = [select id, name, phone from account limit 100];      
string RocordNum51 = acctlist[50].name;
this works fine but I can’t seem get the same result with the following example:
list <sobject> QueryObject = database.query(QueryString);
integer intvar =  QueryObject[50].TheNum 
note that ‘TheNum ’ is the alias from the query string select statement
 
My ultimate goal will be to use a while loop and select the row of the sObject list using an iterating variable. This and many others data points will then be constructed in a wrapped class for charting.
 
Please help
 
Hello All,
 I’m having some trouble wrapping my head around wrapper classes (pun intended). The basics of what I’m trying to accomplish is to create a map where the key is a concatenation of two strings and the value is a wrapper list that holds multiple primitives. I have done some reading but can’t seem to get it working. The error I’m getting is line 30 “Method does not exist or incorrect signature: [List<OfficerStats_CampaignUpdate.CampAggWrperBooked>].add(String, Date, Integer, Integer, Integer)”. Can someone please help me understand what I’m doing wrong.
 
public class OfficerStats_CampaignUpdate {
    
    public list <Campaign> triggerVarNew;
    public list <Campaign> triggerVarOld;
    
	// Main Class Constructor    
    public OfficerStats_CampaignUpdate (list<Campaign> triggerContNew, list<Campaign> triggerContOld){
        triggerVarNew = triggerContNew;
        triggerVarOld = triggerContOld;
        
		// Get list of effected dates and add to set (from new and old trigger records)
        set<date> EffectedDates = new set<date>();    
        for(Campaign TriggValNew : TriggerVarNew){EffectedDates.add(Date.valueof(TriggValNew.End_Date_Time__c));}
        for(Campaign TriggValOld : TriggerVarOld){EffectedDates.add(Date.valueof(TriggValOld.End_Date_Time__c));}
        
        // get agg result list of campaings within specific dates
        list <aggregateResult> CampaignAggResult = ([SELECT Count(id) countid, sum(New_Memberships__c) Memberships, DAY_ONLY(End_Date_time__c) EventDate, sum(referral_total__c) Referrals, Booked_by__c BookedBy, GROUPING(Booked_By__c) GRPBooked  
                                                     FROM Campaign
                                                     WHERE Status = 'Completed'
                                                     AND DAY_ONLY(End_Date_Time__c) in : EffectedDates
                                                     GROUP BY CUBE (Booked_By__c, DAY_ONLY(End_Date_time__c))
                                                     ORDER BY GROUPING (Booked_by__c)]);
        
		// For each agg result line, check to see if bookedby is null, if not null add to list, then add list to    map value   
        map <string,CampAggWrperBooked> WrapperMap = new map <string,CampAggWrperBooked>();
        
        for (AggregateResult ar : CampaignAggResult){
            if(ar.get('BookedBy') != null){
            	list <CampAggWrperBooked> BookedWrapperList =  new list <CampAggWrperBooked>();
                    BookedWrapperList.add(string.valueof(ar.get('bookedBy')), date.valueof(ar.get('EventDate')), integer.valueof(ar.get('Memberships')), integer.valueof(ar.get('Referrals')), integer.valueof(ar.get('countid')));
                
            }
            
        }
        
    }
      
	// Wrapper Class
    public class CampAggWrperBooked {
        public string BookedBy;
        public date EndDate;
        Public integer SumOfMembers;
        public integer SumOfReferrals;
        Public integer EventCount;
		// Wrapper Constructor            
        public CampAggWrperBooked(string BookedByWrap, date EndDateWrap, integer SumOfMembersWrap, integer SumOfReferralsWrap, integer EventCountWrap){
            this.BookedBy = BookedByWrap;
            this.EndDate = EndDateWrap;
            this.SumOfMembers = SumOfMembersWrap;
            this.SumOfReferrals = SumOfReferralsWrap;
            this.EventCount = EventCountWrap;
        }            
    }   
}


 
Hello All,
I'm attempting to write a class that will allow me to take AggregateResults from two unrelated objects and list them on a visualforce page for display and charting. I understand that I will need to use a wrapper class to accomplish this, but for the life of me, I can’t get it to work the way I expect. Although I am getting the information to pass to my visualforce page, when displayed, it shows the entire list in one column as opposed to being iterated. I have been reading the docs for a while now and can’t seem to find out what I’m doing wrong. Any guidance would be greatly appreciated

Apex:
public class ErrorTableClass3 {
    
	public ErrorTableClass3(){
        getWrapperC();
    }
    
    public list<WrapperClass> ErrorTable {get; set;}
    
    public class WrapperClass{
    	public list<integer> Mem {get; set;}
        public list<integer> Err {get; set;}
        public list<string> Errmon {get; set;}
        public list<string> MemMonth {get; set;}
            
        public WrapperClass (list<string> ErrorMonth, list<string> Memmonth, list<integer> Memberships, list<integer> Errors){
            Mem = Memberships;
            Err = Errors;
            ErrMon = ErrorMonth;
            MemMonth = MemMonth;
        }     
    }
  
    Public list<WrapperClass> getWrapperC(){

        list<AggregateResult> MembershipAggList = new list<AggregateResult>([SELECT SUM(New_Memberships__c) Memberships, Calendar_month(event_date__c) EventMonth FROM Campaign WHERE Facilitated_By_MD__C = '005i0000000z0nW'GROUP BY Calendar_month(event_date__c )]);  
        list<AggregateResult> ErrorAggList = new list<AggregateResult>([SELECT count(ID) Errors, Calendar_month (App_sign_Date__c) Datemonth FROM Missing_Info_Errors__C WHERE Officer__c = 'John Smith' AND App_Sign_Date__c = THIS_YEAR GROUP BY Calendar_month(App_Sign_Date__c)]);
        
       	list<integer> MembershipIntList = new list<integer>();
        list<string> MemMonth           = new list<string>();
        list<string> ErrorMonth         = new list<string>();
        list<integer> ErrorIntList      = new list<integer>();
		list<WrapperClass> ErrorTable = new list<WrapperClass>();
        
        for(AggregateResult m : MembershipAggList){
        	MembershipIntList.add(integer.valueOf(m.get('Memberships')));
            MemMonth.add(string.valueOf(m.get('EventMonth')));
       	}
        
        for(AggregateResult e : ErrorAggList){
        	ErrorIntList.add(integer.valueOf(e.get('Errors')));
            ErrorMonth.add(string.valueOf(e.get('DateMonth')));
        }
        

        ErrorTable.add(new WrapperClass(ErrorMonth, MemMonth, MembershipIntList, ErrorIntList));
            return ErrorTable;
        
    }
   
}
Markup:
<apex:page controller="ErrorTableClass3">
    <apex:pageBlock >
			<apex:pageBlockTable value="{!WrapperC}" var="e">
                <apex:column headerValue="Errors" footerValue="Total" value="{!e.Err}" />
                <apex:column headerValue="Memberships" footerValue="Total" value="{!e.Mem}" />
                <apex:column headerValue="Month" footerValue="Total" value="{!e.ErrMon}" />
            </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Result Screenshot
User-added image

 
Hello all,

I have some "working" code that I feel can be much more efficient but am not sure how to go about it any help would be greatly appreciated.

This is the complete working code im using to display fields on a custom visualforce page. I feel like I can reduce the number of SOQL queries by using the Group by Rollup and grouping feature but I’m not sure how parse the results.


Example of query that will give me more than one piece of information (this returns the expected resutls, but im not sure how to capture the various datapoints in apex):
List <AggregateResult> EventAgg =  [SELECT Sum(Total_Memberships__c) MembershipSum, count(ID) CNT, Calendar_month(Event_Date__c) Month, Facilitated_by_MD__c FacilitatedBy, Booked_By__c BookedBy,GROUPING (Facilitated_by_MD__C) FacilGroup, GROUPING (Booked_By__c) BookedGroup, GROUPING (Event_Date__c) monthGroup FROM Campaign WHERE End_Date_Time__c = This_Year GROUP BY ROLLUP (Facilitated_by_MD__c , Booked_By__c, Event_Date__c)];

Complete "working" code:
@testvisible  
Public with sharing class InfoPanelController {

     Public integer PacketsOutstanding = 0;
     public integer PayrollFormsOutstanding = 0;
     public integer BranchReferrals = 0;
     Public integer EventsMTD = 0;
     Public integer ErrorsMTD = 0;
     Public integer ErrorsYTD = 0;
     Public integer MembershipsMTD = 0;
     Public integer MembershipsYTD = 0;
     Public string  UserFullName = UserInfo.getFirstname() + ' ' + UserInfo.getLastname();
        
         
    
List <AggregateResult> PacketResults         =  [SELECT Count(ID)PacketCount FROM Campaign WHERE Facilitated_by_MD__r.id = :UserInfo.getUserId() AND Expecting_packet__c = 'True']; 
    
List <AggregateResult> PayrollResults        =  [SELECT Count(ID)PayrollCount FROM Campaign WHERE Facilitated_by_MD__r.id = :UserInfo.getUserId() AND Payroll_DateStamp__c = null AND   End_Date_Time__c >= Today AND End_Date_Time__c = This_Year AND Status = 'Completed' AND Payroll_Forms__c >0];
                                                  
List <AggregateResult> BranchReferralResults =  [SELECT Count(ID)BranchReferralCount FROM Branch_Referrals__c WHERE Referral_Assigned_to__r.id = :UserInfo.getUserId() AND Referral_Status__c = 'Pending'];
                                                  
List <AggregateResult> EventsMTDResults      =  [SELECT Count(ID)EventsMTDCount FROM Campaign WHERE Booked_by__r.id = :UserInfo.getUserId() AND End_Date_Time__c = This_Month AND status = 'Completed'];                                              
                                                      
List <AggregateResult> ErrorsMTDResults      =  [SELECT Count(ID)ErrorsMTDCount FROM Missing_Info_Errors__c WHERE Officer__c = :userfullname AND App_Sign_Date__c = This_Month AND Known__c = 'Known' ];
    
List <AggregateResult> ErrorsYTDResults      =  [SELECT Count(ID)ErrorsYTDCount FROM Missing_Info_Errors__c WHERE Officer__c = :userfullname AND App_Sign_Date__c = This_Year AND Known__c = 'Known' ];
                                                      
List <AggregateResult> MembershipsMTDResults =  [SELECT Sum(Total_Memberships__c)MembershipsMTDCount FROM Campaign WHERE Booked_by__r.id = :UserInfo.getUserid() AND End_Date_Time__c = This_Month AND Status = 'Completed'];
    
List <AggregateResult> MembershipsYTDResults =  [SELECT Sum(Total_Memberships__c)MembershipsYTDCount FROM Campaign WHERE Booked_by__r.id = :UserInfo.getUserid() AND End_Date_Time__c = This_Year AND Status = 'Completed'];
    
     
       Public integer getpacketsOutstanding(){
            packetsOutstanding = integer.valueof(PacketResults[0].get('PacketCount'));
            Return PacketsOutstanding;
        }
        
        Public integer getPayrollFormsOutstanding(){
            PayrollFormsOutstanding = integer.valueof(PayrollResults[0].get('PayrollCount'));
            Return PayrollFormsOutstanding;
        }
        
        Public integer getBranchReferrals(){
            BranchReferrals = integer.valueof(BranchReferralResults[0].get('BranchReferralCount'));
            Return BranchReferrals;
        }
        
        Public integer getEventsMTD(){
            EventsMTD = integer.valueof(EventsMTDResults[0].get('EventsMTDCount'));
            Return EventsMTD;   
        }
        
        Public integer getErrorsMTD(){
            ErrorsMTD = integer.valueof(ErrorsMTDResults[0].get('ErrorsMTDCount'));
            Return ErrorsMTD;   
        }    
    
        Public integer getErrorsYTD(){
            ErrorsYTD = integer.valueof(ErrorsYTDResults[0].get('ErrorsYTDCount'));
            Return ErrorsYTD;   
        } 
     
        Public integer getMembershipsMTD(){
            MembershipsMTD = integer.valueof(MembershipsMTDResults[0].get('MembershipsMTDCount'));
            If (MembershipsMTD == null)
                MembershipsMTD = 0;
            Return MembershipsMTD;
        }
            
        Public integer getMembershipsYTD(){
            MembershipsYTD = integer.valueof(MembershipsYTDResults[0].get('MembershipsYTDCount'));
            If (MembershipsYTD == null)
                MembershipsYTD = 0;
            Return MembershipsYTD;    
        } 
}

 
Hello Community,
 
I’m attempting to use one SOQL query to get many data point that can be displayed on a Visualforce page. My query returns the expected results but I am not sure of how to parse through the query results and assign them to variables. My thought was that I could simply loop through the results and, based on the conditions, assign them to variables with getters and setters. This does not generate an error, but my page will anything when calling {!MembershipsYTD}. if someone could help point me in the right direction it would be greatly appreciated.

public class MDEventResults 
{

    // Properties
    public integer ThisMonth = date.today().month();
    public integer MembershipsYTD {get; set;}
    public integer MembershipsMTD {get; set;}


    
    // Query Event Data
    List <AggregateResult> EventAgg =  [SELECT Sum(Total_Memberships__c) MembershipSum, count(ID) CNT, Calendar_month(Event_Date__c) Month, Facilitated_by_MD__c FacilitatedBy, Booked_By__c BookedBy,
                                        GROUPING (Facilitated_by_MD__C) FacilGroup, GROUPING (Booked_By__c) BookedGroup, GROUPING (Event_Date__c) monthGroup
                                        FROM Campaign
                                        // WHERE Booked_by__r.id = :UserInfo.getUserid()//
                                        WHERE End_Date_Time__c = This_Year
                                        // AND Status = 'Completed' //
                                        GROUP BY ROLLUP (Facilitated_by_MD__c , Booked_By__c, Event_Date__c)];
    
    // method to parse results
    public void MembershipsYTD() {
        for (AggregateResult ar : EventAgg) {
            if (integer.valueOf(ar.get('monthGroup' )) == ThisMonth &&
                integer.valueOf(ar.get('BookedGroup')) == 1 &&
                integer.valueOf(ar.get('FacilGroup' )) == 1) 
            {
                MembershipsYTD = integer.valueOf(ar.get('MembershipSum'));
                system.debug('MembershipsYTD' + MembershipsYTD);    
            } 
        }
 
    }
}
 
Hello All,
Tried writing a trigger to count donations where the account ID is listed in a reference field but am getting a null pointer error. been looking at this thing for a while and need another pair of eyes on it. I’m still really new to apex in general and am trying to learn. If someone could give me some guidance it would be great appreciated.
 
trigger CountDonations on Donation__c (after insert, after update, after delete) 
{
	set <ID> accountInTriggerSet = new set <ID>();
    set <ID> childAccountSet = new set <ID>();
    
    
    for(Donation__c don : Trigger.new)
        {
            accountInTriggerSet.add(don.Organization__c);
        }
    
    for(account Acct : [SELECT id FROM Account WHERE Parent_site__c IN :accountInTriggerSet])
        {
            childAccountSet.add(acct.Id);
        }
    
    Map <id, aggregateResult> ChildDonationSumMap = new map <id, aggregateResult>([SELECT organization__c AcctID, Sum(Donation_Amount__c)DonSum 
                                                                                   FROM Donation__c 
                                                                                   WHERE organization__C != null 
                                                                                   AND ID IN :childAccountSet 
                                                                                   GROUP BY organization__c]);
    
    
    List <account> updatedAccounts = [SELECT ID, name, Sum_Of_Child_Donations__C FROM account where ID IN :AccountInTriggerSet];
    
    for (account acct : UpdatedAccounts)
    {
        acct.Sum_of_Child_Donations__c = (decimal)childDonationSumMap.get(acct.id).get('DonSum');
        
    }
    update updatedAccounts;

}

 

I’m trying to create a lookup between two custom objects were there is a matching account number field. I would like to create a trigger on ObjectA that says: Whenever ObjectA is created or edited, search ObjectB and see if a record with the same account number exists. If a record exists, take the ID from ObjectB and insert it into the matching ObjectA record as a lookup field. I have been at this for a while and am at a loss. I am very new to APEX and any assistance in pointing me in the right direction would be greatly appreciated.
I have a visualforce page to display some basic account data. The page uses the standard Account controller with a custom extension. Basically I just want the page to display the sum of all the related donations (Donation__c) via  {!TotalDonations }.
My custom controller is intended to get this information using a get method and SOQL query but I just can’t get it to work. I’ve tried several variations of code but have been unsuccessful. If anyone can help point me in the right direction it would be greatly appreciated.
 
 
 
 
 
public with sharing class MyTabbedExtension {
public MyTabbedExtension(ApexPages.StandardController controller) {
}
       
public integer totaldonations(){
return database.query(SELECT Sum(Donation_Amount__c) FROM Donation__c WHERE Parent_Account__c = :ApexPages.currentPage().getParameters().get('ID'));
}
 // THIS WAS JUST ANOTHER ATTEMPT THAT DID NOT WORK  
Public list <Donation__c> getTotalDonations(){    
return totalDonations = [SELECT Sum(Donation_Amount__c) FROM Donation__c WHERE Parent_Account__c = :ApexPages.currentPage().getParameters().get('ID')];
}
   
 
}
Hello Community,

I’m developing a single Visualforce page that displays Visualforce charts in a tabbed layout and need some help with the most efficient way to get my chart data. Currently, I am populating the chart data via GetMethods in my controller, I understand this is a poor design as all methods will run every time the page reloads. Also, my methods are loaded with database queries that makes for long load times.
 
In an ideal state, I would like to initially load the page without calling any method in the controller, then when a button is clicked, call the appropriate method and populate the chart data.
 
If someone could give me some advice on the most efficient way to accomplish it would be greatly appreciated.
 
Thank you,

User-added image
I created a new (boolean) field "FakeFieldTrigger__c" on the contact object, defaut value = FALSE, I would like to change the value to TRUE, but get an error.

List<Contact> recList = [SELECT Id, FakeFieldTrigger__c FROM Contact WHERE FakeFieldTrigger__c = FALSE;  ];
for (Contact rec : recList) {
rec.FakeFieldTrigger__c = TRUE;
}
update recList;


Error:

Line: 1, Column: 5
Unexpected token '<'.

Can you help me update the value of this boolean field, I can then trigger my process in the process builder.

Thanks,

Dave

We have two custom Object Student and College.
I have one custom field in Student fee
And in Parent Total Amount
Whenever student joined to college Total Amount will be update using trigger
What could be my best approach on this; business case: Emails to update fields in salesforce
Templates will have merged fields
Signatory first name
Signatory Last name
Date
Removal date.
it is expected that these fields will  automatically update contact fields when a reponses is received from customers. There should be a capability
of removing the signatory first and last name automatically if the customer wishes to in future with the removal date recorded
What is my best approach? can inbound emails do this? 
please options on achiving this without creating a template are also wellcome. 
I am not a core developer, detailed explanation will be much apreciated
 
  • June 18, 2018
  • Like
  • 0
Hello community,
 
I’m having a difficult time trying to access values from a list of generic sObject. Example:
 
Typically, I would do something like this:
list <account> acctlist = [select id, name, phone from account limit 100];      
string RocordNum51 = acctlist[50].name;
this works fine but I can’t seem get the same result with the following example:
list <sobject> QueryObject = database.query(QueryString);
integer intvar =  QueryObject[50].TheNum 
note that ‘TheNum ’ is the alias from the query string select statement
 
My ultimate goal will be to use a while loop and select the row of the sObject list using an iterating variable. This and many others data points will then be constructed in a wrapped class for charting.
 
Please help
 
Hello All,
 I’m having some trouble wrapping my head around wrapper classes (pun intended). The basics of what I’m trying to accomplish is to create a map where the key is a concatenation of two strings and the value is a wrapper list that holds multiple primitives. I have done some reading but can’t seem to get it working. The error I’m getting is line 30 “Method does not exist or incorrect signature: [List<OfficerStats_CampaignUpdate.CampAggWrperBooked>].add(String, Date, Integer, Integer, Integer)”. Can someone please help me understand what I’m doing wrong.
 
public class OfficerStats_CampaignUpdate {
    
    public list <Campaign> triggerVarNew;
    public list <Campaign> triggerVarOld;
    
	// Main Class Constructor    
    public OfficerStats_CampaignUpdate (list<Campaign> triggerContNew, list<Campaign> triggerContOld){
        triggerVarNew = triggerContNew;
        triggerVarOld = triggerContOld;
        
		// Get list of effected dates and add to set (from new and old trigger records)
        set<date> EffectedDates = new set<date>();    
        for(Campaign TriggValNew : TriggerVarNew){EffectedDates.add(Date.valueof(TriggValNew.End_Date_Time__c));}
        for(Campaign TriggValOld : TriggerVarOld){EffectedDates.add(Date.valueof(TriggValOld.End_Date_Time__c));}
        
        // get agg result list of campaings within specific dates
        list <aggregateResult> CampaignAggResult = ([SELECT Count(id) countid, sum(New_Memberships__c) Memberships, DAY_ONLY(End_Date_time__c) EventDate, sum(referral_total__c) Referrals, Booked_by__c BookedBy, GROUPING(Booked_By__c) GRPBooked  
                                                     FROM Campaign
                                                     WHERE Status = 'Completed'
                                                     AND DAY_ONLY(End_Date_Time__c) in : EffectedDates
                                                     GROUP BY CUBE (Booked_By__c, DAY_ONLY(End_Date_time__c))
                                                     ORDER BY GROUPING (Booked_by__c)]);
        
		// For each agg result line, check to see if bookedby is null, if not null add to list, then add list to    map value   
        map <string,CampAggWrperBooked> WrapperMap = new map <string,CampAggWrperBooked>();
        
        for (AggregateResult ar : CampaignAggResult){
            if(ar.get('BookedBy') != null){
            	list <CampAggWrperBooked> BookedWrapperList =  new list <CampAggWrperBooked>();
                    BookedWrapperList.add(string.valueof(ar.get('bookedBy')), date.valueof(ar.get('EventDate')), integer.valueof(ar.get('Memberships')), integer.valueof(ar.get('Referrals')), integer.valueof(ar.get('countid')));
                
            }
            
        }
        
    }
      
	// Wrapper Class
    public class CampAggWrperBooked {
        public string BookedBy;
        public date EndDate;
        Public integer SumOfMembers;
        public integer SumOfReferrals;
        Public integer EventCount;
		// Wrapper Constructor            
        public CampAggWrperBooked(string BookedByWrap, date EndDateWrap, integer SumOfMembersWrap, integer SumOfReferralsWrap, integer EventCountWrap){
            this.BookedBy = BookedByWrap;
            this.EndDate = EndDateWrap;
            this.SumOfMembers = SumOfMembersWrap;
            this.SumOfReferrals = SumOfReferralsWrap;
            this.EventCount = EventCountWrap;
        }            
    }   
}


 
Hello All,
I'm attempting to write a class that will allow me to take AggregateResults from two unrelated objects and list them on a visualforce page for display and charting. I understand that I will need to use a wrapper class to accomplish this, but for the life of me, I can’t get it to work the way I expect. Although I am getting the information to pass to my visualforce page, when displayed, it shows the entire list in one column as opposed to being iterated. I have been reading the docs for a while now and can’t seem to find out what I’m doing wrong. Any guidance would be greatly appreciated

Apex:
public class ErrorTableClass3 {
    
	public ErrorTableClass3(){
        getWrapperC();
    }
    
    public list<WrapperClass> ErrorTable {get; set;}
    
    public class WrapperClass{
    	public list<integer> Mem {get; set;}
        public list<integer> Err {get; set;}
        public list<string> Errmon {get; set;}
        public list<string> MemMonth {get; set;}
            
        public WrapperClass (list<string> ErrorMonth, list<string> Memmonth, list<integer> Memberships, list<integer> Errors){
            Mem = Memberships;
            Err = Errors;
            ErrMon = ErrorMonth;
            MemMonth = MemMonth;
        }     
    }
  
    Public list<WrapperClass> getWrapperC(){

        list<AggregateResult> MembershipAggList = new list<AggregateResult>([SELECT SUM(New_Memberships__c) Memberships, Calendar_month(event_date__c) EventMonth FROM Campaign WHERE Facilitated_By_MD__C = '005i0000000z0nW'GROUP BY Calendar_month(event_date__c )]);  
        list<AggregateResult> ErrorAggList = new list<AggregateResult>([SELECT count(ID) Errors, Calendar_month (App_sign_Date__c) Datemonth FROM Missing_Info_Errors__C WHERE Officer__c = 'John Smith' AND App_Sign_Date__c = THIS_YEAR GROUP BY Calendar_month(App_Sign_Date__c)]);
        
       	list<integer> MembershipIntList = new list<integer>();
        list<string> MemMonth           = new list<string>();
        list<string> ErrorMonth         = new list<string>();
        list<integer> ErrorIntList      = new list<integer>();
		list<WrapperClass> ErrorTable = new list<WrapperClass>();
        
        for(AggregateResult m : MembershipAggList){
        	MembershipIntList.add(integer.valueOf(m.get('Memberships')));
            MemMonth.add(string.valueOf(m.get('EventMonth')));
       	}
        
        for(AggregateResult e : ErrorAggList){
        	ErrorIntList.add(integer.valueOf(e.get('Errors')));
            ErrorMonth.add(string.valueOf(e.get('DateMonth')));
        }
        

        ErrorTable.add(new WrapperClass(ErrorMonth, MemMonth, MembershipIntList, ErrorIntList));
            return ErrorTable;
        
    }
   
}
Markup:
<apex:page controller="ErrorTableClass3">
    <apex:pageBlock >
			<apex:pageBlockTable value="{!WrapperC}" var="e">
                <apex:column headerValue="Errors" footerValue="Total" value="{!e.Err}" />
                <apex:column headerValue="Memberships" footerValue="Total" value="{!e.Mem}" />
                <apex:column headerValue="Month" footerValue="Total" value="{!e.ErrMon}" />
            </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Result Screenshot
User-added image

 
Hello Community,
 
I’m attempting to use one SOQL query to get many data point that can be displayed on a Visualforce page. My query returns the expected results but I am not sure of how to parse through the query results and assign them to variables. My thought was that I could simply loop through the results and, based on the conditions, assign them to variables with getters and setters. This does not generate an error, but my page will anything when calling {!MembershipsYTD}. if someone could help point me in the right direction it would be greatly appreciated.

public class MDEventResults 
{

    // Properties
    public integer ThisMonth = date.today().month();
    public integer MembershipsYTD {get; set;}
    public integer MembershipsMTD {get; set;}


    
    // Query Event Data
    List <AggregateResult> EventAgg =  [SELECT Sum(Total_Memberships__c) MembershipSum, count(ID) CNT, Calendar_month(Event_Date__c) Month, Facilitated_by_MD__c FacilitatedBy, Booked_By__c BookedBy,
                                        GROUPING (Facilitated_by_MD__C) FacilGroup, GROUPING (Booked_By__c) BookedGroup, GROUPING (Event_Date__c) monthGroup
                                        FROM Campaign
                                        // WHERE Booked_by__r.id = :UserInfo.getUserid()//
                                        WHERE End_Date_Time__c = This_Year
                                        // AND Status = 'Completed' //
                                        GROUP BY ROLLUP (Facilitated_by_MD__c , Booked_By__c, Event_Date__c)];
    
    // method to parse results
    public void MembershipsYTD() {
        for (AggregateResult ar : EventAgg) {
            if (integer.valueOf(ar.get('monthGroup' )) == ThisMonth &&
                integer.valueOf(ar.get('BookedGroup')) == 1 &&
                integer.valueOf(ar.get('FacilGroup' )) == 1) 
            {
                MembershipsYTD = integer.valueOf(ar.get('MembershipSum'));
                system.debug('MembershipsYTD' + MembershipsYTD);    
            } 
        }
 
    }
}
 
Hello All,
Tried writing a trigger to count donations where the account ID is listed in a reference field but am getting a null pointer error. been looking at this thing for a while and need another pair of eyes on it. I’m still really new to apex in general and am trying to learn. If someone could give me some guidance it would be great appreciated.
 
trigger CountDonations on Donation__c (after insert, after update, after delete) 
{
	set <ID> accountInTriggerSet = new set <ID>();
    set <ID> childAccountSet = new set <ID>();
    
    
    for(Donation__c don : Trigger.new)
        {
            accountInTriggerSet.add(don.Organization__c);
        }
    
    for(account Acct : [SELECT id FROM Account WHERE Parent_site__c IN :accountInTriggerSet])
        {
            childAccountSet.add(acct.Id);
        }
    
    Map <id, aggregateResult> ChildDonationSumMap = new map <id, aggregateResult>([SELECT organization__c AcctID, Sum(Donation_Amount__c)DonSum 
                                                                                   FROM Donation__c 
                                                                                   WHERE organization__C != null 
                                                                                   AND ID IN :childAccountSet 
                                                                                   GROUP BY organization__c]);
    
    
    List <account> updatedAccounts = [SELECT ID, name, Sum_Of_Child_Donations__C FROM account where ID IN :AccountInTriggerSet];
    
    for (account acct : UpdatedAccounts)
    {
        acct.Sum_of_Child_Donations__c = (decimal)childDonationSumMap.get(acct.id).get('DonSum');
        
    }
    update updatedAccounts;

}

 

I’m trying to create a lookup between two custom objects were there is a matching account number field. I would like to create a trigger on ObjectA that says: Whenever ObjectA is created or edited, search ObjectB and see if a record with the same account number exists. If a record exists, take the ID from ObjectB and insert it into the matching ObjectA record as a lookup field. I have been at this for a while and am at a loss. I am very new to APEX and any assistance in pointing me in the right direction would be greatly appreciated.