I am new to Apex coding any help would be greatly appreciated. This is an update trigger and I am trying to check if the hard-coded field lists were updated.
However, I am getting an error in the initialization of the fieldList (the fields I am hard-coding here are the ones I want to check if they were updated).
Error Line
sObjectField[] fieldList = new sObjectField[]{
Account.Name,Account.Industry
};
Error Message
Error received: Initial expression is of incorrect type, expected: Schema.SObjectField but was: String.
Complete Code
trigger UpdateChildOrg on Account (after update) {
Set<id> AccountIdSet=new Set<id>();
Schema.sObjectField[] changedFields = new list<Schema.sObjectField> ();
for(Account account:trigger.new) {
accountIdSet.add(account.id);
sObjectField[] fieldList = new sObjectField[] {
Account.Name, Account.Industry
};
system.debug(fieldList);
SObject o1 = Trigger.oldMap.get(account.id);
SObject o2 = Trigger.newMap.get(account.id);
system.debug('o1 is '+ o1);
system.debug('o2 is '+ o2);
for (Schema.sObjectField field : fieldList) {
system.debug('field is : '+field);
Object v1 = o1.get(field);
Object v2 = o2.get(field);
if (v1 != v2) {
changedFields.add(field);
}
}
system.debug('changed fields are'+changedFields);
if(changedFields.size()>0){
HTTPAccountCallout.updateOrder(account.id,changedFields);
}
}
}
What am I doing wrong? How can I fix it?