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
Jim MontgomeryJim Montgomery 

Error Loop Variable must be of type account

Getting error "Loop Variable Mut be of Type Account Line 7".
Here is my code.
No classes named accoutn.

trigger HasWorkPaperManager on Account (after insert, after update) {

    Map<ID, Account> parentAccount = new Map<ID, Account>();
    List<Id> listIds = new List<Id>();
    List<Id> LineItems = new List<Id>();

    for (AMS_Inventory_Rollup__c childObj : Trigger.new) {
        listIds.add(childObj.AccountID__c);
        LineItems.add(childObj.Id);
    }
  
    parentAccount = new Map<Id, Account>([SELECT id,Has_WorkPaper_Manager__c,(Select id from Ams_inventory_rollups__r where name = '511000') FROM account WHERE ID IN :listIds]);
   
    for (AMS_Inventory_Rollup__c AMSInventoryRollup: Trigger.new){
         Account myParentAccount = parentAccount.get(AMSInventoryRollup.Account);
        if(parentAccount.containsKey(AMSInventoryRollup.Account) && parentaccount.get(AMSInventoryRollup.Account).AMSInventoryRollups__r.size() > 0)
        {
            myParentAccount.Has_WorkPaper_Manager__c = true;
        }
        else
        {
            myParentAccount.Has_WorkPaper_Manager__c = false ;
        }
    }
    update parentAccount.values();
 }
Best Answer chosen by Jim Montgomery
RaidanRaidan
Your trigger is on Account object, so this line won't work:

    for (AMS_Inventory_Rollup__c childObj : Trigger.new) {

You can only have this line with the Trigger.new

for (Account acct : Trigger.new) {

 

All Answers

RaidanRaidan
Your trigger is on Account object, so this line won't work:

    for (AMS_Inventory_Rollup__c childObj : Trigger.new) {

You can only have this line with the Trigger.new

for (Account acct : Trigger.new) {

 
This was selected as the best answer
Jim MontgomeryJim Montgomery
Thank you, sometimes just need anothet set of eyes. Trigger should ahve been on the AMS Inventory Rollup object.
RaidanRaidan
Hi Jim,

Please mark the answer as solved. Thanks!