You need to sign in to do that
Don't have an account?
Kumar5
How to bulkify the below code
Hi Team,
I want to populate account id value into the field (BISM_Officer__c) of object Clarity_Effort__c.
Below is the requirement in brief
I have two objects Clarity and Account. If any record is created with out BISM_Officer__c then, there is field Resource_Name__c in Clarity object and in Account there is field Clarity_Effort_Resource_Name__c if these two are matching, the accountId of value with Clarity_Effort_Resource_Name__c need to popualte in Clarity record. The below code is working for single record, but not bulk records.
Would you please guide me with above requirement.
trigger AccountPopulate on Clarity_Effort__c (before insert, before update)
{
String AccountId;
Map<String,List<Clarity_Effort__c>> AccountClarityList = new Map <String,List<Clarity_Effort__c>>();
List<Account> AccountList = new List<Account> ();
// List<Clarity_Effort__c> UpdateClarityList = new List<Clarity_Effort__c>();
List<Clarity_Effort__c> NewClartiryList= new List<Clarity_Effort__c>();
List<string> ClarityWithoutAccounts = new List<string>();
for (Clarity_Effort__c CE : Trigger.new)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
if(CE.BISM_Officer__c == null)
{
ClarityWithoutAccounts.add(CE.Resource_Name__c);
NewClartiryList.add(CE);
}
}
system.debug( 'Naresh'+ ClarityWithoutAccounts);
}
AccountList = [SELECT Id FROM Account WHERE Clarity_Effort_Resource_Name__c IN : ClarityWithoutAccounts];
for(Account Acc : AccountList)
{
if(!AccountClarityList.containsKey(Acc.Id))
{
AccountClarityList.put(Acc.id, new List<Clarity_Effort__c>());
AccountClarityList.get(Acc.Id);
AccountId= Acc.Id;
}
system.debug('AccountListCL'+AccountClarityList);
for (Clarity_Effort__c CEU : NewClartiryList )
{
CEU.BISM_Officer__c = AccountId;
// UpdateClarityList.add(CEU);
}
}
}
Thanks,
Kumar
I want to populate account id value into the field (BISM_Officer__c) of object Clarity_Effort__c.
Below is the requirement in brief
I have two objects Clarity and Account. If any record is created with out BISM_Officer__c then, there is field Resource_Name__c in Clarity object and in Account there is field Clarity_Effort_Resource_Name__c if these two are matching, the accountId of value with Clarity_Effort_Resource_Name__c need to popualte in Clarity record. The below code is working for single record, but not bulk records.
Would you please guide me with above requirement.
trigger AccountPopulate on Clarity_Effort__c (before insert, before update)
{
String AccountId;
Map<String,List<Clarity_Effort__c>> AccountClarityList = new Map <String,List<Clarity_Effort__c>>();
List<Account> AccountList = new List<Account> ();
// List<Clarity_Effort__c> UpdateClarityList = new List<Clarity_Effort__c>();
List<Clarity_Effort__c> NewClartiryList= new List<Clarity_Effort__c>();
List<string> ClarityWithoutAccounts = new List<string>();
for (Clarity_Effort__c CE : Trigger.new)
{
if (Trigger.isInsert || Trigger.isUpdate)
{
if(CE.BISM_Officer__c == null)
{
ClarityWithoutAccounts.add(CE.Resource_Name__c);
NewClartiryList.add(CE);
}
}
system.debug( 'Naresh'+ ClarityWithoutAccounts);
}
AccountList = [SELECT Id FROM Account WHERE Clarity_Effort_Resource_Name__c IN : ClarityWithoutAccounts];
for(Account Acc : AccountList)
{
if(!AccountClarityList.containsKey(Acc.Id))
{
AccountClarityList.put(Acc.id, new List<Clarity_Effort__c>());
AccountClarityList.get(Acc.Id);
AccountId= Acc.Id;
}
system.debug('AccountListCL'+AccountClarityList);
for (Clarity_Effort__c CEU : NewClartiryList )
{
CEU.BISM_Officer__c = AccountId;
// UpdateClarityList.add(CEU);
}
}
}
Thanks,
Kumar
Below is the modified code. Hope it works.
Thanks,
Saraz
All Answers
Below is the modified code. Hope it works.
Thanks,
Saraz
Add a line - update NewClartiryList;
next to the line 27
Thanks,
Saraz