+ Start a Discussion
RovRov 

expression must be a list type: SOBJECT:CustomAccount__c

public with sharing class Alert {  
	
	@future
	public static void processCustomAccounts(list<String> names, Map<String,String> alert) {
		
          
          // list to store the custom accounts to update
          List<CustomAccount__c> customaccountsToUpdate = new List<CustomAccount__c>();
            
          // iterate through the list of custom accounts to process
          for (CustomAccount__c a : [Select Id, Name,Alert__c From CustomAccount__c where Name like :names]) {
               string [] truncateagain = a.Name.split('-'); 
               string tpart1 = truncateagain.get(0);
               string tpart2 = truncateagain.get(1);
               string addfirsttwoparts = tpart1 + '-' + tPart2 + '%';
               
               // if alert value in the map passed in the method above is not null
			   // replace all existing custom accounts with this new value.
			   if(alert.values()!=null){
                             	a.Alert__c = alert.get(addfirsttwoparts);
               } 
			   // if alert value in the map passed in the method above is null
			   // make this null value as the value of the 1st record found in the SOQL			   
			   else if(alert.values()==null){
               	
               	id myalert = a[0].Alert__c;   // error: expression must be a list type: SOBJECT:CustomAccount__c               	a.Alert__c = myalert;
               	system.debug('now what!!!!!!!');
               	
               	
               	}
               // add the custom accounts to the list to update
               customaccountsToUpdate.add(a);
          }
          
                   AlertProcessorControl.inFutureContext = true;
                    
          if(!customaccountsToUpdate.isEmpty()){
          	update customaccountsToUpdate;
          }
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

public with sharing class Alert {  
    
    @future
    public static void processCustomAccounts(list<String> names, Map<String,String> alert) {
        
          
          // list to store the custom accounts to update
          List<CustomAccount__c> customaccountsToUpdate = new List<CustomAccount__c>();
         List<CustomAccount__c> customAccounts = [Select Id, Name,Alert__c From CustomAccount__c where Name like :names];
          // iterate through the list of custom accounts to process
          for (CustomAccount__c a : customAccounts) {
               string [] truncateagain = a.Name.split('-');
               string tpart1 = truncateagain.get(0);
               string tpart2 = truncateagain.get(1);
               string addfirsttwoparts = tpart1 + '-' + tPart2 + '%';
               
               // if alert value in the map passed in the method above is not null
               // replace all existing custom accounts with this new value.
               if(alert.values()!=null){
                                 a.Alert__c = alert.get(addfirsttwoparts);
               }
               // if alert value in the map passed in the method above is null
               // make this null value as the value of the 1st record found in the SOQL               
               else if(alert.values()==null){
                   
                   id myalert = customAccounts[0].Alert__c;   // error: expression must be a list type: SOBJECT:CustomAccount__c                   
        a.Alert__c = myalert;
                   system.debug('now what!!!!!!!');
                   
                   
                   }
               // add the custom accounts to the list to update
               customaccountsToUpdate.add(a);
          }
          
                   AlertProcessorControl.inFutureContext = true;
                    
          if(!customaccountsToUpdate.isEmpty()){
              update customaccountsToUpdate;
          }
    }
}

All Answers

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

public with sharing class Alert {  
    
    @future
    public static void processCustomAccounts(list<String> names, Map<String,String> alert) {
        
          
          // list to store the custom accounts to update
          List<CustomAccount__c> customaccountsToUpdate = new List<CustomAccount__c>();
         List<CustomAccount__c> customAccounts = [Select Id, Name,Alert__c From CustomAccount__c where Name like :names];
          // iterate through the list of custom accounts to process
          for (CustomAccount__c a : customAccounts) {
               string [] truncateagain = a.Name.split('-');
               string tpart1 = truncateagain.get(0);
               string tpart2 = truncateagain.get(1);
               string addfirsttwoparts = tpart1 + '-' + tPart2 + '%';
               
               // if alert value in the map passed in the method above is not null
               // replace all existing custom accounts with this new value.
               if(alert.values()!=null){
                                 a.Alert__c = alert.get(addfirsttwoparts);
               }
               // if alert value in the map passed in the method above is null
               // make this null value as the value of the 1st record found in the SOQL               
               else if(alert.values()==null){
                   
                   id myalert = customAccounts[0].Alert__c;   // error: expression must be a list type: SOBJECT:CustomAccount__c                   
        a.Alert__c = myalert;
                   system.debug('now what!!!!!!!');
                   
                   
                   }
               // add the custom accounts to the list to update
               customaccountsToUpdate.add(a);
          }
          
                   AlertProcessorControl.inFutureContext = true;
                    
          if(!customaccountsToUpdate.isEmpty()){
              update customaccountsToUpdate;
          }
    }
}

This was selected as the best answer
mauro_offermannmauro_offermann

The 'a' variable is your 'for' CustomAccount__c variable, it isn't a List.
Try it:
id myalert = a.Alert__c;

RovRov

Thanks for your help @saikishore and Maur0