You need to sign in to do that
Don't have an account?
sparktest
@ future causing error in class - creating detail records from master record insert - more than 100
I have an after update trigger that fires the below class. I am creating a number of related records depending on values in the master object. I have seen some of the examples of @future and I am not sure if I can even do this.
Is there a better way? I am bumping up against the limit and I was hoping @future would take care of it, but I get an error of
"Save error: Unsupported parameter type LIST:SOBJECT:Site_Lease_Contract__c SiteLeaseCumCostUpdate/src/classes SiteLeaseFncTblClass.cls line 4"
When I try to save as below (minus the '@future' is works fine)
Code:
public class SiteLeaseFncTblClass { @future public static void SiteLeaseFncTblTrigger(Site_Lease_Contract__c[] newSiteLeaseFncTbl) { for (Integer i = 0; i < Trigger.new.size(); i++) { List<SiteFnc__c> followuprecords = new List<SiteFnc__c>(); Boolean GT = newSiteLeaseFncTbl[i].Generate_Table__c; Boolean AR = newSiteLeaseFncTbl[i].Auto_Renewed__c; Double Months = newSiteLeaseFncTbl[i].Lease_Term_In_Months__c; Double RMonths = newSiteLeaseFncTbl[i].Renew_Term__c; Double RTerms = newSiteLeaseFncTbl[i].Renew_Addl_Terms__c; String LeaseID = newSiteLeaseFncTbl[i].id; Date MonthBegin = newSiteLeaseFncTbl[i].Start_Date__c; Double escamt = (newSiteLeaseFncTbl[i].Escalation_Amount__c/100)+1; Double escmth = newSiteLeaseFncTbl[i].Escalation_Month__c; Double RentToPay = newSiteLeaseFncTbl[i].Initial_Rent__c; Double SLD = newSiteLeaseFncTbl[i].Straight_Line_Depr__c; if (GT == True) { Double j = Months; If (AR == True) { j = Months + (RMonths * RTerms); } Integer Count = 1; Integer CycleInsert = 1; for (Integer k = 0; k < j; k++) { if (escmth == k+1) { RentToPay = RentToPay * escamt; } if (k+1 > escmth) { Count = Count + 1; } if (Count == 12) { Count = 1; RentToPay = RentToPay * escamt; } SiteFnc__c SiteFnc = new SiteFnc__c( Site_Lease__c = LeaseID, Date__c = MonthBegin.addmonths(k), Cumulative_Def_Rent_Obl__c = SLD * (k+1), Rent__c = RentToPay); followuprecords.add(SiteFnc); } insert followuprecords; } } } }
thanks Albert and JR,
DOH,
I was trying to figure out the complicated answer and missed the one right in front of me. I moved the insert 'up' one level and it works great now.
Just for the sake of argument though, I would like to have a better understanding on how to do the asynchronous insert. I found examles on how to do it within one object, but when it comes to doing a related/master-detail insert of multiple records for the detail I haven't found one yet. Any advice, just basic is fine so I am not digging around in the wrong place, would be great on that.
I saw the exclusion of SObjects on the @future and figured that was an issue, but I didn't know how else to pull in the Master object so I could use it to insert the related detail records. I am new to the syntax/usage of java/apex so I apologize for the elementary questions.
Thanks,
What error are you getting? Maybe you are still having a bulk related issue with your for loop.
You need to move your list creation outside of the loop, and move the insert outside of the loop.