You need to sign in to do that
Don't have an account?
madhavi mishra
Trigger Handler
Hi ,
I am new in devlopment side. Somebody help me to write Trigger but I do not how to write Trigger Handler. Please help..
My Trigger:
trigger populateParentAccount on account(after insert) {
Account[] updates = new Account[0];
Set<Id> accountIds = new Set<Id>();
for(Lead record: [SELECT ConvertedAccountId, Agency_Account__c FROM Lead WHERE ConvertedAccountId = :Trigger.new ORDER BY ConvertedDate DESC]) {
// Avoid multiple leads with same account
if(!accountIds.add(record.ConvertedAccountId)) {
updates.add(new Account(Id=record.ConvertedAccountId, ParentId=record.Agency_Account__c));
}
}
update updates;
}
I am new in devlopment side. Somebody help me to write Trigger but I do not how to write Trigger Handler. Please help..
My Trigger:
trigger populateParentAccount on account(after insert) {
Account[] updates = new Account[0];
Set<Id> accountIds = new Set<Id>();
for(Lead record: [SELECT ConvertedAccountId, Agency_Account__c FROM Lead WHERE ConvertedAccountId = :Trigger.new ORDER BY ConvertedDate DESC]) {
// Avoid multiple leads with same account
if(!accountIds.add(record.ConvertedAccountId)) {
updates.add(new Account(Id=record.ConvertedAccountId, ParentId=record.Agency_Account__c));
}
}
update updates;
}
https://developer.salesforce.com/page/Apex_Code_Best_Practices
Here is an example of Trigger with Handler I have done before for a Case Trigger. Review to have some direction on how to create the Handler etc.
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000IK8dQAG
Regards
Andrew