You need to sign in to do that
Don't have an account?
AnnaT
Loop through fieldname
Please help me...
I have 20 E-mail fields named Email1__c, Email2__c, Email3__c,.....Email20__c.
What I want to do is loop thorugh these fields and input value.
Hereis my code.
Alerts__c alerts =new Alerts__c(); for(integer j=1;j==MailList.size();j++){ String iStr = String.Valueof(j); String fieldname='Email'+iStr+'__c'; alerts.get(fieldname)='test@test.com'; }
But the following error occured.
Expression cannot be assigned
Please tell me how to solve this problem...
Thanks in advance for your help.
Anna
Alerts__c alerts =new Alerts__c();
for(integer j=1;j==MailList.size();j++){
String iStr = String.Valueof(j);
String fieldname='Email'+iStr+'__c';
alerts.put(fieldname,'test@test.com');
}
All Answers
Instead of looping directly put all the 20 fields and assign.
Alerts__c alerts =new Alerts__c();
for(integer j=1;j==MailList.size();j++){
String iStr = String.Valueof(j);
String fieldname='Email'+iStr+'__c';
alerts.put(fieldname,'test@test.com');
}
Thank you very much for your help!!
You had the right idea :)