You need to sign in to do that
Don't have an account?
Olver_Bassov
I'm getting this error on my Trigger.
I believe the part of the code that is causing this is:
public static void ProcessScheduledMaintenanceEmailsTrigger(
List<Scheduled_Maintenance_Email__c> sched_new,
List<Scheduled_Maintenance_Email__c> sched_old) {
for (integer i = 0; i < sched_new.size(); i++) {
if (sched_new[i].Email_Triggered__c == true && sched_old[i].Email_Triggered__c == false) {
// To send the email, change the state to the scheduled renewal state, which
// will cause the opportunityAutoRenewalStateChangedTrigger to fire, which
// in turn will call SendOrScheduleEmail() below
List<Opportunity> opps = [ SELECT
Id,
Auto_Renewal_State__c
FROM
Opportunity
WHERE
Id= :sched_new[i].Opportunity__c
];
If someone knows how to fix this it will be much appreciatted. I have been googling about it but haven't understood how I'd take the select out of the loop.
Thank you
System.LimitException: Too many SOQL queries: 101
I'm getting this error on my Trigger.
I believe the part of the code that is causing this is:
public static void ProcessScheduledMaintenanceEmailsTrigger(
List<Scheduled_Maintenance_Email__c> sched_new,
List<Scheduled_Maintenance_Email__c> sched_old) {
for (integer i = 0; i < sched_new.size(); i++) {
if (sched_new[i].Email_Triggered__c == true && sched_old[i].Email_Triggered__c == false) {
// To send the email, change the state to the scheduled renewal state, which
// will cause the opportunityAutoRenewalStateChangedTrigger to fire, which
// in turn will call SendOrScheduleEmail() below
List<Opportunity> opps = [ SELECT
Id,
Auto_Renewal_State__c
FROM
Opportunity
WHERE
Id= :sched_new[i].Opportunity__c
];
If someone knows how to fix this it will be much appreciatted. I have been googling about it but haven't understood how I'd take the select out of the loop.
Thank you
You are using SOQL query in for loop. You need to apply this SOQL query outside the for loop :
I have made some changes in code.
public static void ProcessScheduledMaintenanceEmailsTrigger(List<Scheduled_Maintenance_Email__c> sched_new, List<Scheduled_Maintenance_Email__c> sched_old) {
//Set ot hold Opportunity Id
Set<String> setOppIds = new Set<String>();
for (integer i = 0; i < sched_new.size(); i++) {
if (sched_new[i].Email_Triggered__c == true && sched_old[i].Email_Triggered__c == false) {
//Add Opportunity In set
setOppIds.add(:sched_new[i].Opportunity__c);
}
}
List<Opportunity> opps = [ SELECT Id, Auto_Renewal_State__c FROM Opportunity WHERE Id IN : setOppIds];
}
When I try to compile I'm getting `Duplicate variable: i (attempt to re-create the variable with type: integer)`
The two lines with for ( integer = i ... is not compiling
What should I do ? Should I change the second for to another variable like j or Should I just use the i without defining it again ?
I'm beginner with apex.
Thank you.
Thanks for all the help guys. It was very appreciated.
I'm trying to compile your code but is giving me an error on this line
setOppIds.add(:sched_new[i].Opportunity__c);
error -> expect right parenthesis found :
Do you know how I can fix this ?
Thanks
I just made the typo mistake.
try this one :
setOppIds.add(sched_new[i].Opportunity__c);