A requirement is to create a Case automatically whenever a Contact is added to an Account with the AccountType field set to 'Premium'. The Case should include the Contact's name in the description and be assigned to the Account Owner. Please make video on that
@sfdcninjas15 сағат бұрын
Sure Rupesh I will create a video on it this week Thanks for the scenario
@srikanthpanjagala19 сағат бұрын
thank you sir you have best teaching skils
@swapnilbawaskar958321 сағат бұрын
can we use aggegrate function in line no 56 i.e. count aggegrate funcction to store the count ? if possible, could you pls paste the querry.. will be really helpful
@swapnilbawaskar958322 сағат бұрын
can you please explain why we used oldmap on line no 11.
@goldylodhi21162 күн бұрын
❤
@teluguraju9813 күн бұрын
Excellent 👌
@rajpabnani8183 күн бұрын
Keep Going 🔥🔥 Thank You for you videos.
@Vlogswithved4 күн бұрын
❤❤❤lovely
@fredericklane7458 күн бұрын
Nice tutorial series. How do we endure that if a field in Billing Address is blank, that it cannot be saved because it's not equal to the already-save shipping address. And, what about when an existing Account has Billing Address updated?
@chatwithsubhra113 күн бұрын
Very nice !!!
@goldylodhi211614 күн бұрын
🎉
@rachitlodhi340414 күн бұрын
Explain more about this
@prabhavgoel92715 күн бұрын
❤
@KhushbuSharma-t5w15 күн бұрын
Very informative 👌
@goldylodhi211615 күн бұрын
Nice
@AbhishekMishra-ps1oq15 күн бұрын
How to use metazoa
@kumareshghosh559315 күн бұрын
Bhai thoda demo dikha deta to sehi raheta
@ananthkapartimusunuri968716 күн бұрын
Hello Ninja, I recently took interview where they asked me : How can you Write a trigger with look up using the relationship as master detail.
@ankitverma906223 күн бұрын
Good work! Make more videos like this.👍
@skmukleshali768325 күн бұрын
hi your logic is not working if i not select any Tech farm when update can u chack please and reply me
@shubhampatidar-w7c25 күн бұрын
1) On lead object if email is present check contact with same email, if there is no contact then create contact with same email and link with lead where lead is having contactId as field. If Email is already present then assign that contact with the same Lead. i was asked this trigger in my interview
@kumareshghosh559323 күн бұрын
Lead and contact are not related to any relationship, I think your scenario is wrong,it could be task instead of lead, or you can create a custom field on lead to make the lookup relationship between lead and contact.
@raviteja-x4u26 күн бұрын
can anyone write a code with help class it would be helpful much to beginners. please anyone provide with a help class .
@goldylodhi211627 күн бұрын
Good 🎉
@ajeetsinghrathore32627 күн бұрын
Sir can you explain from basic !! I can't understand this process
@sindhunethra369828 күн бұрын
Is this for 2 years of experience?
@bhai-fs4lh28 күн бұрын
Bro make mistakes like this....we will also learn how to rectify mistakes in codes..
@kumareshghosh5593Ай бұрын
It was a bit confusing to follow this code bro unlike your other trigger explanation, I know it's a little complex scenario but things could have been a but more simpler vai.
@AwesomeRiyaАй бұрын
Plz can some1 send code in comments
@AwesomeRiyaАй бұрын
Hey plz can u paste the corrected code (Final code) as its confusing following the video
@AbhishekMishra-ps1oqАй бұрын
@SFDCNinja where you are populating the existingShareMap?
@EliF.ShalinskiАй бұрын
Great video Thank u This is my approach, will cover (insert and update). public class AccountTriggerHandler { public static void shareAccWithSecOwnerSFDC_64(List<Account> accTriggerNew,Map<Id,Account> accTriggerOldMap){ Map<Id,Id> accIdToOwnerId = new Map<Id,Id>(); List<AccountShare> listAccShare = new List<AccountShare>(); Account oldAcc; for (Account newAcc : accTriggerNew) { if (accTriggerOldMap!=null) { oldAcc=accTriggerOldMap.get(newAcc.Id); if (newAcc.SecondaryOwner__c!=oldAcc.SecondaryOwner__c) { if (newAcc.SecondaryOwner__c!=null) { listAccShare.add(createAccShareInstance(newAcc.Id,newAcc.SecondaryOwner__c)); } if (oldAcc.SecondaryOwner__c!=null) { accIdToOwnerId.put(newAcc.Id, oldAcc.SecondaryOwner__c); } } }else { if (newAcc.SecondaryOwner__c!=null) { listAccShare.add(createAccShareInstance(newAcc.Id,newAcc.SecondaryOwner__c)); } } } if (!listAccShare.isEmpty()) { Database.insert(listAccShare,false); } if (!accIdToOwnerId.isEmpty()) { List<AccountShare> listAccShareForDelete =[SELECT Id FROM AccountShare WHERE AccountId IN:accIdToOwnerId.keySet() AND UserOrGroupId IN:accIdToOwnerId.values()]; if (!listAccShareForDelete.isEmpty()) { Database.delete(listAccShareForDelete, false); } } } private static AccountShare createAccShareInstance(Id accId,Id userId){ AccountShare accShare = new AccountShare(); accShare.AccountId=accId; accShare.UserOrGroupId=userId; accShare.AccountAccessLevel='Edit'; accShare.OpportunityAccessLevel='Edit'; return accShare; } }
@goldylodhi2116Ай бұрын
Great explanation 🎉
@shalalalalooАй бұрын
Hi Sir, do you see any issue in the below piece of code for this problem: public static void afterInsertHandlerScenario12(List<Case> caseList){ Set<Account> accToUpd=new Set<Account>{}; List<Account> accUpd=new List<Account>{}; if(!caseList.isEmpty()){ for(Case c:caselist){ if(c.AccountId != NULL){ accToUpd.add(new Account(id=c.AccountId,Latest_Case_Inserted__c=String.valueof(c.CaseNumber))); } } if(!accToUpd.isEmpty()){ accUpd.addall(accToUpd); UPDATE accUpd; } } }
@anubhavgupta2573Ай бұрын
Here is the updated version of the code which will not give an error when we edit and save the record without changing the name - trigger AccountTrigger on Account (before insert,before update){ if(trigger.isBefore){ Set<String> accNames = new Set<String>(); if(trigger.isInsert){ for(Account a:Trigger.new){ accNames.add(a.Name); } if(!accNames.isEmpty()){ List<Account> getDuplicateAccounts = [SELECT Id,Name FROM Account WHERE Name IN :accNames]; if(!getDuplicateAccounts.isEmpty()){ for(Account a:Trigger.new){ a.Name.addError('Insert ERROR: An Account with same name exists, Please try a different name'); } } } } if(trigger.isUpdate){ for(Account a:trigger.new){ if(a.Name != trigger.oldMap.get(a.Id).Name){ accNames.add(a.Name); } } if(!accNames.isEmpty()){ List<Account> getDuplicateAccounts = [SELECT Id,Name FROM Account WHERE Name IN :accNames]; if(!getDuplicateAccounts.isEmpty()){ for(Account a:Trigger.new){ a.Name.addError('Update ERROR: An Account with same name exists, Please try a different name'); } } } } }
@HelloitsmeReenaАй бұрын
trigger accTrigger on Account (after Update){ Map<Id,Account> accMap = new Map<Id,Account>(); if(trigger.isAfter && trigger.isUpdate) { if(trigger.new.isEmpty()){ for(Account acc : trigger.new){ if(trigger.oldMap.get(acc.Id).Phone!= acc.Phone){ accMap.put(acc.id,acc); } } } } List<Contact> conList = [Select Id,AccountId,Phone from Contact where AccountId IN : accMap.keySet()]; List<Contact> listToUpdateContacts = new List<Contact>(); if(!conList.isEmpty()) { for(Contact con : conList) { con.Phone = accMap.get(con.AccountId).Phone; listToUpdateContacts.add(con); } } if(!listToUpdateContacts.isEmpty()) { update listToUpdateContacts; } } please tell me how to solve these errors. i am not able to run this trigger. the errors are, Illegal assignment from List<Contact> to List<Contact> - line 12 Variable does not exist: AccountId - line 18 Variable does not exist: Phone - line 18 DML requires SObject or SObject list type: List<Contact> - line 24
@HelloitsmeReenaАй бұрын
Thank you so much Sir, i have been having a hard time understanding triggers and now i understand why i write each line it is very useful. there are many youtube channels when scenarios gets tougher then they don't explain why they wrote certain lines and for beginners its really stressful. thank you for the effort you have put in Sir. Thank you.
@dharmeshtayade4856Ай бұрын
you explain very well but why did you not create a separate class for that trigger?
@codymate7579Ай бұрын
Hii Sir, Can we write this Code? public static void updateAccountPicklist(List<Opportunity> oppList, Map<Id, Opportunity> oppMap){ if(!oppList.isEmpty()){ Set<Id> accIds = new Set<Id>(); List<Account> accList = new List<Account>(); for(Opportunity opp: oppList){ if(opp.AccountId != null && opp.StageName !=null){ Opportunity oldMap = oppMap.get(opp.Id); if(oldMap!=null){ if(opp.StageName != oldMap.StageName){ accIds.add(opp.AccountId); } else if(opp.AccountId != oldMap.AccountId){ accIds.add(opp.AccountId); accIds.add(oldMap.AccountId); } } else{ accIds.add(opp.AccountId); } } } if(!accIds.isEmpty()){ Map<Id, Account> accMap = new Map<Id, Account>([Select Id, Account_Status__c from Account Where Id IN: accIds]); if(!accMap.isEmpty()){ for(Opportunity opp: oppList){ if(accMap.containsKey(opp.AccountId)){ if(opp.StageName == 'Closed Won'){ Account acc = new Account(Id = opp.AccountId, Account_Status__c = 'Closed'); accList.add(acc); }else{ Account acc = new Account(Id = opp.AccountId, Account_Status__c = 'Open'); accList.add(acc); } } } } if(!accList.isEmpty()){ update accList; } } } }
@jatinneelay5926Ай бұрын
there should be if else and in else we should add non duplicate record in map so that within trigger scope we dont insert duplicates
@noumandanish5762Ай бұрын
Instead of using a for loop to get a set of accountId you can directly just query on opportunity with the required filters [Select Id, StageName from Opportunity where AccountId In: trigger new and Isclosed = false and Account.Close_all_Opps__c = true and Probability>= 70]; And then with just one for loop on oppList we can update the value of Stage to Closed Won and update oppList
@MrAnshulkАй бұрын
Simpler solution trigger conTrigger on contact(after update){ Map<Id,String> accountMapToUpdate = new map<Id,String>(); for(Contact con:trigger.new){ if(con.description__c!=null && con.description__c!=trigger.oldMap.get(con.Id).description__c){ accountMapToUpdate.put(con.accountId,con.description__c); } } List<Account> accountsToUpdate = new List<Account>(); if(!accountMapToUpdate.isEmpty()){ for(Id accid: accountMapToUpdate.keySet()){ Account acc = new Account( Id = accid; acc.Acc_description__c = accountMapToUpdate.get(accid) ) accountsToUpdate.add(acc); } } if (!accountsToUpdate.isEmpty()) { update accountsToUpdate; } }
@MichelleMartinez-s6gАй бұрын
Sam Spur
@divijrdАй бұрын
For this Scenario, We can use the Record trigger Flow- Is it Possible ?
@EliF.ShalinskiАй бұрын
Thank u for video This is my approach public class ContactTriggerHandler { public static void updateAccRelCons_SFDC53(List<Contact> conTriggerNew,Map<Id,Contact> conTriggerNewMap){ set<Id> accIds = new set<Id>(); List<Contact> updateCons = new List<Contact>(); for (Contact newCon : conTriggerNew) { if (newCon.AccountId!=null) { accIds.add(newCon.AccountId); } } if (!accIds.isEmpty()) { for (Contact eachCon : [SELECT Id,New_Contact__c FROM Contact WHERE AccountId IN:accIds] ) { if (conTriggerNewMap.containsKey(eachCon.Id) && eachCon.New_Contact__c!=true) { eachCon.New_Contact__c=true; updateCons.add(eachCon); }else if (!conTriggerNewMap.containsKey(eachCon.Id) && eachCon.New_Contact__c==true) { eachCon.New_Contact__c=false; updateCons.add(eachCon); } } if (!updateCons.isEmpty()) { update updateCons; } } } }
@abhijeetvaishnab7738Ай бұрын
trigger CaseTrigger on Case(after insert,after update,after delete,after undelete){ TriggerDispatcher dispatcher = new TriggerDispatcher(); dispatcher.dispatch('CaseTriggerHandler',Trigger.OperationType); } public interface ITriggerInterface{ void beforeInsert(List<SObject> newSObjectList); void afterInsert(List<SObject> newSObjectList,Map<Id,SObject> newSObjectMap); void beforeUpdate(List<SObject> newSObjectList,Map<Id,SObject> newSObjectMap,List<SObject> oldSObjectList,Map<Id,SObject> oldSObjectMap); void afterUpdate(List<SObject> newSObjectList,Map<Id,SObject> newSObjectMap,List<SObject> oldSObjectList,Map<Id,SObject> oldSObjectMap); void beforeDelete(List<SObject> oldSObjectList,Map<Id,SObject> oldSObjectMap); void afterDelete(List<SObject> oldSObjectList,Map<Id,SObject> oldSObjectMap); void afterUnDelete(List<SObject> newSObjectList,Map<Id,SObject> newSObjectMap); } public class TriggerDispatcher{ public void dispatch(String handlerName,System.TriggerOperation operationType){ ITriggerInterface handler = Type.forName(handlerName).newInstance(); Switch on operationType{ when BEFORE_INSERT{ handler.beforeInsert(Trigger.new); } when AFTER_INSERT{ handler.beforeInsert(Trigger.new,Trigger.newMap); } when BEFORE_UPDATE{ handler.beforeInsert(Trigger.new,Trigger.newMap,Trigger.old,Trigger.oldMap); } when AFTER_UDPATE{ handler.beforeInsert(Trigger.new,Trigger.newMap,Trigger.old,Trigger.oldMap); } when BEFORE_DELETE{ handler.beforeInsert(Trigger.old,Trigger.oldMap); } when AFTER_DELETE{ handler.beforeInsert(Trigger.old,Trigger.oldMap); } when AFTER_UNDELETE{ handler.beforeInsert(Trigger.new,Trigger.newMap); } } } } public class CaseTriggerHandler{ public void beforeInsert(List<Case> newCaseList){ } public void afterInsert(List<Case> newCaseList,Map<Id,Case> newCaseMap){ Set<Id> accSet = new Set<Id>(); for(Case c : newCaseList){ if(c.AccountId!=null){ accSet.add(c.AccountId); } } if(accSet.size()>0){ CaseService.process(accSet); } } public void beforeUpdate(List<Case> newCaseList,Map<Id,Case> newCaseMap,List<Case> oldCaseList,Map<Id,Case> oldCaseMap){ } public void afterUpdate(List<Case> newCaseList,Map<Id,Case> newCaseMap,List<Case> oldCaseList,Map<Id,Case> oldCaseMap){ Set<Id> accSet = new Set<Id>(); for(Case c : newCaseList){ if(c.AccountId!=oldCaseMap.get(c.Id).AccountId){ if(c.AccountId!=null){ accSet.add(c.AccountId); accSet.add(oldCaseMap.get(c.Id).AccountId); } else{ accSet.add(oldCaseMap.get(c.Id).AccountId); } } if(c.Status!=oldCaseMap.get(c.Id).Status){ accSet.add(c.AccountId); } } if(accSet.size()>0){ CaseService.process(accSet); } } public void beforeDelete(List<Case> oldCaseList,Map<Id,Case> oldCaseMap){ } public void afterDelete(List<Case> oldCaseList,Map<Id,Case> oldCaseMap){ Set<Id> accSet = new Set<Id>(); for(Case c : oldCaseList){ if(c.AccountId!=null){ accSet.add(c.AccountId); } } if(accSet.size()>0){ CaseService.process(accSet); } } public void afterUnDelete(List<Case> newCaseList,Map<Id,Case> newCaseMap){ Set<Id> accSet = new Set<Id>(); for(Case c : newCaseList){ if(c.AccountId!=null){ accSet.add(c.AccountId); } } if(accSet.size()>0){ CaseService.process(accSet); } } } public class CaseService{ public static void process(Set<Id> accSet){ List<Account> accLst = new List<Account>(); for(AggregateResult agg : [Select AccountId,Count(Status) countCase,Status from Case where AccountId IN accSet Group By AccountId,Status]){ Account acc = new Account(); acc.Id = agg.get('AccountId'); if(agg.get('Status')=='New'){ acc.num_NewCase__c = agg.get('countCase'); } else if(agg.get('Status')=='Working'){ acc.num_WorkingCase__c = agg.get('countCase'); } else if(agg.get('Status')=='Escalated'){ acc.num_EscalatedCase__c = agg.get('countCase'); } accLst.add(acc); } if(!accLst.isEmpty()){ update accLst; } } }
@abhijeetvaishnab7738Ай бұрын
provide trigger operations also like in this case it shd be - trigger CaseTrigger on Case(after update,after delete,after undelete){}
@abhijeetvaishnab7738Ай бұрын
trigger CaseTrigger on Case(after update){ CaseTriggerHandler.afterUpdate(Trigger.new,Trigger.oldMap); } public class CaseTriggerHandler{ public void afterUpdate(List<Case> newCaseLst,Map<Id,Case> oldCaseMap){ Set<Id> accSet = new Set<Id>(); for(Case c : newCaseLst){ if(c.createTask__c!=oldCaseMap.get(c.Id).createTask__c && c.AccountId!=null){ accSet.add(c.AccountId); } } if(accSet.size()>0){ CaseService.process(accSet); } } } public class CaseService{ public static void process(Set<Id> accSet){ List<Task> tLst = new List<tLst>(); for(Contact con : [Select Id from Contact where Id IN accSet and isPrimary__c=true]){ Task t = new Task(); t.WhoId = con.Id; t.Subject = 'Follow Up'; t.priority = 'Medium'; tLst.add(t); } if(!tLst.isEmpty()){ insert tLst; } } }
@spblore2 ай бұрын
Instead of map..to add all Opportunity amount we can use totalAmount+=opp.Amount; It provides a simple solution and then just use String.valueof(totalAmount)
@blackdragon66562 ай бұрын
why we are using before delete event instead of after delete ?
@OtakRajCodesАй бұрын
I think it should have been an after delete event . Please let me know if you figured out why he used before delete .
@MAHANTYCRIC2 ай бұрын
what kind of trigger scenarios expected for 10 years experience in salesforce?