I need to update existing records. when i am trying to update single record in developer console(anonymous window) by passing ID in where clause. But, when i try to update multiple records i'am facing error. can any one please tell me is way of updating correct or not.
This is the query for update single record:
Accreditation__c accr = [SELECT Id, Account__c, Business_Plan__c
FROM Accreditation__c WHERE id = 'a5PU0000000PCVX'];
accr.Business_Plan__c = [select Name from Business_Plan__c
where Partner_Account__c = :accr.Account__c
and Year__c = '2016'].id;
update accr;
This is the query for update multiple records:
Accreditation__c[] accr = [SELECT Id,Business_Plan__c,Account__c FROM Accreditation__c WHERE isActive__c = true AND is_branch__c = true limit 2];
system.debug('accr size = '+accr.size());
if(!accr.isEmpty()){
for(Accreditation__c accrdt : accr)
accrdt.Business_Plan__c = [select Name from Business_Plan__c where Year__c = '2016' AND Partner_Account__c = :accrdt.Account__c];
update accr;
}
The error is while updating multiple records:
Illegal assignment from List to Id
Can anybody please suggest me to avoid this error or what is fastest way to update existing records.