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
a!a! 

Hi, Error in list : line 7, column 18: Loop variable must be of type String

List<string> s =new list<string>{'CESSSSS'};
List<string> s1= new list<string>{'WA'};
List<string> s2= new list<string>{'NZ'};
List<account> acc = new list<account>();
for (account a :[select id,ownerid,billingstate from account where type='Prospect' and name != 's'])
{
    for (account b : s1)
    {
    if(b.billingstate == a.billingstate)
    { 
        a.ownerid='00591128657gfH5';
        acc.add(a);
    }
    }
}
 update acc;

 

Naidu PothiniNaidu Pothini
List<string> s =new list<string>{'CESSSSS'};
List<string> s1= new list<string>{'WA'};
List<string> s2= new list<string>{'NZ'};
List<account> acc = new list<account>();
for (account a :[select id,ownerid,billingstate from account where type='Prospect' and name != 's'])
{
    for(String b : s1) //for (account b : s1)
    {
        if(b == a.BillingState) //if(b.billingstate == a.billingstate)
        { 
            a.ownerid='00591128657gfH5';
        }
    }
acc.add(a); } update acc;

 

JayDP123JayDP123

'for (account b : s1)'  - is saying for each account in this list of strings. But a String List doesn't have any accounts, it has Strings.