You need to sign in to do that
Don't have an account?

Variable does not exist: AccountIds
Hi,
Can someone help me with this trigger? I'm getting this error upon saving it:
Error: Compile Error: Variable does not exist: AccountIds at line 9 column 13
Here's my trigger:
trigger updatePCFPMPRopp on Master_Tracker__c (after insert) {
Master_Tracker__c mt = trigger.new[0];
if(mt.Product_Code__c == 'PCFP' && (mt.GLAS_Offer_Status__c == 'Initiated' || mt.GLAS_Offer_Status__c == 'Offer in Review'))
List<Id> AccountIds = new List<Id>();
for (Integer i=0;i<Trigger.new.size();i++){
{
AccountIds.add(Trigger.new[i].Account_Name__c);
}
}
List<Opportunity> OppList = new List<Opportunity>([SELECT Id,AccountId FROM Opportunity WHERE RecordTypeId = '012d0000000go7t' and Closed = false]);
for (Opportunity opp: OppList){
opp.StageName = 'Closed Won'; }
update OppList;
}
Can someone help me with this trigger? I'm getting this error upon saving it:
Error: Compile Error: Variable does not exist: AccountIds at line 9 column 13
Here's my trigger:
trigger updatePCFPMPRopp on Master_Tracker__c (after insert) {
Master_Tracker__c mt = trigger.new[0];
if(mt.Product_Code__c == 'PCFP' && (mt.GLAS_Offer_Status__c == 'Initiated' || mt.GLAS_Offer_Status__c == 'Offer in Review'))
List<Id> AccountIds = new List<Id>();
for (Integer i=0;i<Trigger.new.size();i++){
{
AccountIds.add(Trigger.new[i].Account_Name__c);
}
}
List<Opportunity> OppList = new List<Opportunity>([SELECT Id,AccountId FROM Opportunity WHERE RecordTypeId = '012d0000000go7t' and Closed = false]);
for (Opportunity opp: OppList){
opp.StageName = 'Closed Won'; }
update OppList;
}
Declare the list called AccountIds at the very top. So that it is availble to the rest of the code.
The opening and closing braces are incorrect casuing a scope problem.
The final update takes place on a list of opportunities that has got nothing to do with the list of Account Ids that you have prepared. It is missing from the query.
If required please specify the entire logic that you are trying to implement. We can then have a logiccaly correct working solution.
For the time being please take a look at this code.
trigger updatePCFPMPRopp on Master_Tracker__c (after insert) {
Master_Tracker__c mt = trigger.new[0];
List<Id> AccountIds = new List<Id>();
if(mt.Product_Code__c == 'PCFP' && (mt.GLAS_Offer_Status__c == 'Initiated' || mt.GLAS_Offer_Status__c == 'Offer in Review')){
for (Integer i=0;i<Trigger.new.size();i++){
AccountIds.add(Trigger.new[i].Account_Name__c);
}
}
// ---- here you should check if account id list has some values then include that in the query or some other logic
// there is no relation between this portion of the code and the previous lines
List<Opportunity> OppList = new List<Opportunity>([SELECT Id,AccountId FROM Opportunity WHERE RecordTypeId = '012d0000000go7t' and Closed = false]);
for (Opportunity opp: OppList){
opp.StageName = 'Closed Won';
}
update OppList;
}
And probably you can consider using RecordType.DeveloperName instead of Id to filter the query ?