Sir Could you please explain below trigger scenario write a trigger to update number of opportunities assigned to a user in a custom tab. Note : it should increase count if any opportunities created and assigned to user and it should increase and decrease if the the opportunity transferred from one user to another
Great video.
Thanks!
Sir Could you please explain below trigger scenario
write a trigger to update number of opportunities assigned to a user in a custom tab.
Note : it should increase count if any opportunities created and assigned to user and it should increase and decrease if the the opportunity transferred from one user to another
Hi abhijit sorry for late reply, i will create a video on this scenario for sure just give me some time bro.
@@sfdcninjas No worries sir... Will wait for the video... Thank you for accepting my scenario question sir🙏
@@sfdcninjasHi Sir... If possible could you do video one, please!
Nice explanation
Keep watching
A simpler version of the abpve code (Feedback or suggestions are welcomed):
trigger AccountTrigger on Account (before update) {
Set accIds = new Set();
if(Trigger.isBefore && Trigger.isUpdate){
for(Account a: Trigger.new){
if(Trigger.oldMap.get(a.Id).Active__c == 'Active' && a.Active__c == 'Inactive')
accIds.add(a.Id);
}
List conList = [Select Id from Contact where AccountId IN: accIds and Primary_Contact__c=true];
for(Account a: Trigger.new){
if(Trigger.oldMap.get(a.Id).Active__c == 'Active' && a.Active__c == 'Inactive')
{
if(conList.size() > 0){
a.addError('You cannot delete this Acc since it contains a Primary contact');
}
}
}
}
}