• Anthony Mealand
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I have a button that calls a VisualForce page that I would like to overwrite the field level security i.e. fields that are read only will become editable in the VisualForce Page. I have created a the Class that acts without sharing and queries the relevant fields and returns them. The class and Visualforce page will both load, but the fields are still ready only. Any help would be appreciated!
Class
public without sharing class MASIExtension {

        private final CustomObject__c INC;

    // The extension constructor initializes the private member
    // variable INC by using the getRecord method from the standard
    // controller.
    public MASIExtension(ApexPages.StandardController stdController) {
        this.INC = (CustomObject__c)stdController.getRecord();
    }
    CustomObject__c I = [SELECT id, Name, customfield1__c, customfield2__c, 
                                            FROM CustomObject__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];



    public CustomObject__c getRecordName() {
        return I;
    }

    public PageReference save(){
        update I;
        return null;
    }
}

Visualforce page
<apex:page standardController="CustomObject__c" extensions="MASIExtension">
    <apex:form >
        <apex:pageBlock title="Enter MASI">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>                
            </apex:pageBlockButtons>
 
            <apex:pageblockSection title="Legal Guardian" > 
                <apex:inputText value="{!CustomObject__c.customfield1__c}"/>            
                <apex:inputField value="{!CustomObject__c.customfield2__c}"/>
                <apex:inputField value="{!INC.Name_of_legal_guardian__c}"/>      
            </apex:pageblockSection>                
              
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hello,

I have the below class that is called by a trigger. The Class runs through 2 lists of objects comparing them. One list is created by the trigger and the other is queried. The issue I am facing is that if I put my SOQL query inside of a loop, I will hit 'too many SOQL queries' limit if the trigger has > 100 records, however, if I query outside of the loop, I get the 'too many query rows' error.

To solve this, I'd like to run a batch which I haven't done before. I think I've worked out how to call the batch (commented in original code), but for this to work, I think need to either:

A) Pass the trigger list into the batch 
B) Return the queried list back into this class
C) Run another query in the batch to evaluate which records are being triggered 

I can't really work out how to do A or B, but I think it might have to do with a constructor maybe? (apologies - Im new to this and this is my frist trigger). If it's simple, I'd rather do this than go to option C (but I will if necessary).

I have posted below the class and the batch class. Any direction for this would be very appreciated.

Thanks!


public class SalesTrackingHandler {
    public void GetSalesData(List<School_Activities__c> SAS, List<School_Activities__c> OldSAS){
        List<Sales_Tracker__c> STS = New List<Sales_Tracker__c>(); // create a list of trackers that will be eventually entered to the system      
        
        Integer EOI = 0; // initiate the counting metrics
        Integer Paid = 0;
        Integer SU = 0;
        integer Count = -1;
        for(School_Activities__c SA : SAS){                        // Runs through all activities triggered
            Count = Count + 1;
            School_Activities__c OldSA = OldSAS.get(Count);        // finds the corresponding record details from before the record was saved
            if(SA.Sales_Tracker_Pendulum__c <> OldSA.Sales_Tracker_Pendulum__c){    // compares the old and new values of the 
                //BatchInclusionDetails Batch = New BatchInclusionDetails(SA);
                //Database.executeBatch(Batch);
                
                
                
                List<Inclusion_Details__c> INCS = [SELECT Id, School_ID__c, Lead_Source__c, Date_payment_received_WF__c,Sign_up_date__c,CreatedDate,Contact__r.NCS_Application_Primary_Season__c
                                                   from Inclusion_Details__c where Contact_Record_Type__c ='Young Person' AND Sales_Tracker_criteria__c = 'TRUE' AND
                                                      Sales_Tracker_Identifier__c like : '%' + SA.School__c + '%'];   // queries the contacts attached to this school for this season. Performed in loop to narrow search results below 50,000 limit
                Date Commence = date.newinstance(SA.Date_Sales_Tracking_commences__c.year(), 
                                         SA.Date_Sales_Tracking_commences__c.month(), SA.Date_Sales_Tracking_commences__c.day()); // sets datetime valid to compare created date against
                EOI = 0; // resets counting metrics
                Paid = 0;
                SU = 0;
                for(Inclusion_Details__c INC : INCS){            // loops through Inclusion detail records to assess against sales tracking metrics
                    if(SA.School__c == INC.School_ID__c && INC.Contact__r.NCS_Application_Primary_Season__c == SA.Season_Name__c){
                        IF(INC.Lead_Source__c == 'TRUE' && INC.CreatedDate >= Commence){      // checking criteria of EOI
                            EOI = EOI + 1;
                        }
                        if(INC.Date_payment_received_WF__c <> NULL){           // checking criteria of Paid
                            Paid = Paid +1;
                            if(INC.Sign_up_date__c <> NULL){                   // checking criteria of SU
                                SU = SU +1;
                            }                  
                        }                  
                    }
                }
                Sales_Tracker__c ST = new Sales_Tracker__c();        // create relevant Sales tracker record 
                    Date Yesterday = System.today() -1;
                ST.Name = SA.School__c + Yesterday.format();
                ST.School_Activity__c = SA.Id;
                ST.EOIs__c = EOI;
                ST.Paid__c = Paid;
                ST.SU__c = SU;
                   ST.Date__c = Yesterday;
                STS.add(ST);
                system.debug(ST);
            }
        }
        Database.insert(STS);         // insert all Sales tracker records to the system
    }
}



public class SalesTrackingHandler {
    public void GetSalesData(List<School_Activities__c> SAS, List<School_Activities__c> OldSAS){
        List<Sales_Tracker__c> STS = New List<Sales_Tracker__c>(); // create a list of trackers that will be eventually entered to the system      
        
        Integer EOI = 0; // initiate the counting metrics
        Integer Paid = 0;
        Integer SU = 0;
        integer Count = -1;
        for(School_Activities__c SA : SAS){                        // Runs through all activities triggered
            Count = Count + 1;
            School_Activities__c OldSA = OldSAS.get(Count);        // finds the corresponding record details from before the record was saved
            if(SA.Sales_Tracker_Pendulum__c <> OldSA.Sales_Tracker_Pendulum__c){    // compares the old and new values of the 
                //BatchInclusionDetails Batch = New BatchInclusionDetails(SA);
                //Database.executeBatch(Batch);
                
                
                
                List<Inclusion_Details__c> INCS = [SELECT Id, School_ID__c, Lead_Source__c, Date_payment_received_WF__c,Sign_up_date__c,CreatedDate,Contact__r.NCS_Application_Primary_Season__c
                                                   from Inclusion_Details__c where Contact_Record_Type__c ='Young Person' AND Sales_Tracker_criteria__c = 'TRUE' AND
                                                      Sales_Tracker_Identifier__c like : '%' + SA.School__c + '%'];   // queries the contacts attached to this school for this season. Performed in loop to narrow search results below 50,000 limit
                Date Commence = date.newinstance(SA.Date_Sales_Tracking_commences__c.year(), 
                                         SA.Date_Sales_Tracking_commences__c.month(), SA.Date_Sales_Tracking_commences__c.day()); // sets datetime valid to compare created date against
                EOI = 0; // resets counting metrics
                Paid = 0;
                SU = 0;
                for(Inclusion_Details__c INC : INCS){            // loops through Inclusion detail records to assess against sales tracking metrics
                    if(SA.School__c == INC.School_ID__c && INC.Contact__r.NCS_Application_Primary_Season__c == SA.Season_Name__c){
                        IF(INC.Lead_Source__c == 'TRUE' && INC.CreatedDate >= Commence){      // checking criteria of EOI
                            EOI = EOI + 1;
                        }
                        if(INC.Date_payment_received_WF__c <> NULL){           // checking criteria of Paid
                            Paid = Paid +1;
                            if(INC.Sign_up_date__c <> NULL){                   // checking criteria of SU
                                SU = SU +1;
                            }                  
                        }                  
                    }
                }
                Sales_Tracker__c ST = new Sales_Tracker__c();        // create relevant Sales tracker record 
                    Date Yesterday = System.today() -1;
                ST.Name = SA.School__c + Yesterday.format();
                ST.School_Activity__c = SA.Id;
                ST.EOIs__c = EOI;
                ST.Paid__c = Paid;
                ST.SU__c = SU;
                   ST.Date__c = Yesterday;
                STS.add(ST);
                system.debug(ST);
            }
        }
        Database.insert(STS);         // insert all Sales tracker records to the system
    }
}
Hello,

I have the below class that is called by a trigger. The Class runs through 2 lists of objects comparing them. One list is created by the trigger and the other is queried. The issue I am facing is that if I put my SOQL query inside of a loop, I will hit 'too many SOQL queries' limit if the trigger has > 100 records, however, if I query outside of the loop, I get the 'too many query rows' error.

To solve this, I'd like to run a batch which I haven't done before. I think I've worked out how to call the batch (commented in original code), but for this to work, I think need to either:

A) Pass the trigger list into the batch 
B) Return the queried list back into this class
C) Run another query in the batch to evaluate which records are being triggered 

I can't really work out how to do A or B, but I think it might have to do with a constructor maybe? (apologies - Im new to this and this is my frist trigger). If it's simple, I'd rather do this than go to option C (but I will if necessary).

I have posted below the class and the batch class. Any direction for this would be very appreciated.

Thanks!


public class SalesTrackingHandler {
    public void GetSalesData(List<School_Activities__c> SAS, List<School_Activities__c> OldSAS){
        List<Sales_Tracker__c> STS = New List<Sales_Tracker__c>(); // create a list of trackers that will be eventually entered to the system      
        
        Integer EOI = 0; // initiate the counting metrics
        Integer Paid = 0;
        Integer SU = 0;
        integer Count = -1;
        for(School_Activities__c SA : SAS){                        // Runs through all activities triggered
            Count = Count + 1;
            School_Activities__c OldSA = OldSAS.get(Count);        // finds the corresponding record details from before the record was saved
            if(SA.Sales_Tracker_Pendulum__c <> OldSA.Sales_Tracker_Pendulum__c){    // compares the old and new values of the 
                //BatchInclusionDetails Batch = New BatchInclusionDetails(SA);
                //Database.executeBatch(Batch);
                
                
                
                List<Inclusion_Details__c> INCS = [SELECT Id, School_ID__c, Lead_Source__c, Date_payment_received_WF__c,Sign_up_date__c,CreatedDate,Contact__r.NCS_Application_Primary_Season__c
                                                   from Inclusion_Details__c where Contact_Record_Type__c ='Young Person' AND Sales_Tracker_criteria__c = 'TRUE' AND
                                                      Sales_Tracker_Identifier__c like : '%' + SA.School__c + '%'];   // queries the contacts attached to this school for this season. Performed in loop to narrow search results below 50,000 limit
                Date Commence = date.newinstance(SA.Date_Sales_Tracking_commences__c.year(), 
                                         SA.Date_Sales_Tracking_commences__c.month(), SA.Date_Sales_Tracking_commences__c.day()); // sets datetime valid to compare created date against
                EOI = 0; // resets counting metrics
                Paid = 0;
                SU = 0;
                for(Inclusion_Details__c INC : INCS){            // loops through Inclusion detail records to assess against sales tracking metrics
                    if(SA.School__c == INC.School_ID__c && INC.Contact__r.NCS_Application_Primary_Season__c == SA.Season_Name__c){
                        IF(INC.Lead_Source__c == 'TRUE' && INC.CreatedDate >= Commence){      // checking criteria of EOI
                            EOI = EOI + 1;
                        }
                        if(INC.Date_payment_received_WF__c <> NULL){           // checking criteria of Paid
                            Paid = Paid +1;
                            if(INC.Sign_up_date__c <> NULL){                   // checking criteria of SU
                                SU = SU +1;
                            }                  
                        }                  
                    }
                }
                Sales_Tracker__c ST = new Sales_Tracker__c();        // create relevant Sales tracker record 
                    Date Yesterday = System.today() -1;
                ST.Name = SA.School__c + Yesterday.format();
                ST.School_Activity__c = SA.Id;
                ST.EOIs__c = EOI;
                ST.Paid__c = Paid;
                ST.SU__c = SU;
                   ST.Date__c = Yesterday;
                STS.add(ST);
                system.debug(ST);
            }
        }
        Database.insert(STS);         // insert all Sales tracker records to the system
    }
}



public class SalesTrackingHandler {
    public void GetSalesData(List<School_Activities__c> SAS, List<School_Activities__c> OldSAS){
        List<Sales_Tracker__c> STS = New List<Sales_Tracker__c>(); // create a list of trackers that will be eventually entered to the system      
        
        Integer EOI = 0; // initiate the counting metrics
        Integer Paid = 0;
        Integer SU = 0;
        integer Count = -1;
        for(School_Activities__c SA : SAS){                        // Runs through all activities triggered
            Count = Count + 1;
            School_Activities__c OldSA = OldSAS.get(Count);        // finds the corresponding record details from before the record was saved
            if(SA.Sales_Tracker_Pendulum__c <> OldSA.Sales_Tracker_Pendulum__c){    // compares the old and new values of the 
                //BatchInclusionDetails Batch = New BatchInclusionDetails(SA);
                //Database.executeBatch(Batch);
                
                
                
                List<Inclusion_Details__c> INCS = [SELECT Id, School_ID__c, Lead_Source__c, Date_payment_received_WF__c,Sign_up_date__c,CreatedDate,Contact__r.NCS_Application_Primary_Season__c
                                                   from Inclusion_Details__c where Contact_Record_Type__c ='Young Person' AND Sales_Tracker_criteria__c = 'TRUE' AND
                                                      Sales_Tracker_Identifier__c like : '%' + SA.School__c + '%'];   // queries the contacts attached to this school for this season. Performed in loop to narrow search results below 50,000 limit
                Date Commence = date.newinstance(SA.Date_Sales_Tracking_commences__c.year(), 
                                         SA.Date_Sales_Tracking_commences__c.month(), SA.Date_Sales_Tracking_commences__c.day()); // sets datetime valid to compare created date against
                EOI = 0; // resets counting metrics
                Paid = 0;
                SU = 0;
                for(Inclusion_Details__c INC : INCS){            // loops through Inclusion detail records to assess against sales tracking metrics
                    if(SA.School__c == INC.School_ID__c && INC.Contact__r.NCS_Application_Primary_Season__c == SA.Season_Name__c){
                        IF(INC.Lead_Source__c == 'TRUE' && INC.CreatedDate >= Commence){      // checking criteria of EOI
                            EOI = EOI + 1;
                        }
                        if(INC.Date_payment_received_WF__c <> NULL){           // checking criteria of Paid
                            Paid = Paid +1;
                            if(INC.Sign_up_date__c <> NULL){                   // checking criteria of SU
                                SU = SU +1;
                            }                  
                        }                  
                    }
                }
                Sales_Tracker__c ST = new Sales_Tracker__c();        // create relevant Sales tracker record 
                    Date Yesterday = System.today() -1;
                ST.Name = SA.School__c + Yesterday.format();
                ST.School_Activity__c = SA.Id;
                ST.EOIs__c = EOI;
                ST.Paid__c = Paid;
                ST.SU__c = SU;
                   ST.Date__c = Yesterday;
                STS.add(ST);
                system.debug(ST);
            }
        }
        Database.insert(STS);         // insert all Sales tracker records to the system
    }
}

When I select "Create New contact", I get the screen asking me to Select Contact Record type.  After I make my selection and click Continue, I am presented with the same screen.  Again, I make the same choice and THEN the New Contact Edit screen is presented. 

 

We are based on the NPSP.

 

Thanks for your help.