function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

need help move my selecte statement from my for loop (trigger)

Hi i have a trigger in my custom object and it hit governor limit due to select statment in my for loop. now i would like to move my statement out. can anyone help? here is my trigger:

trigger CalculateMorgage on Property__c (before insert) {
   for(Property__c pp:{        
        List <House_Type__c> ht = [SELECT ID, Property_Type__c  FROM House_Type__c WHERE Range__c =: pp.range__c and Quantity__c =: pp.p_quantity__c];

          for(House_Type__c htt:ht){
                 pp.type__c = htt.Property_Type__c ;


Andy BoettcherAndy Boettcher
How is your schema setup?  Is House_Type__c a child of Property__c?
it is not. House_Type__c is a reference object to get the type based on Range__c & Quantity__c. it will look like this:

Range__c    Quantity__c     Property_Type__c
R_10                   10                        AC01
R_10                   50                        AC02
R_10                   500                      AC03

so if my quantity is 25 and range is R_10 it will return AC02 & AC03 but i need only AC02