Apex Triggers - 29 (Trigger Interview Question)

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • Revolutionize your Salesforce experience with Titan's powerful products
    Create and automate custom document templates directly from Salesforce - titandxp.com/p...
    Share, manage, and track the progress of e-signatures directly from Salesforce - titandxp.com/p...
    Create, automate, and track custom web forms directly from Salesforce - titandxp.com/p...
    Design and deploy dynamic no-code web portals and applications from Salesforce - titandxp.com/p...
    Automate your entire organization’s processes with digital workflow - titandxp.com/p...
    Create, automate, and track custom web surveys directly from Salesforce - titandxp.com/p...

ความคิดเห็น • 6

  • @chvenkatareddy5794
    @chvenkatareddy5794 ปีที่แล้ว +1

    Hi Can you please create trigger for the following interview question?
    Task (Email__c) >> Account > Contact > (Primary_contact__c)/Email
    1) There are 10 contacts on account
    2) If I select any OR Create a new contact as Primary_contact__c = true && Email not blank
    - then Email of particular contact should be reflected on task Email__c field. Task already there we need to update on existing task

    • @sfdcninjas
      @sfdcninjas  ปีที่แล้ว

      Please go through this trigger and let me know whether it is working or not
      trigger UpdateTaskEmailOnPrimaryContact on Contact (after insert, after update) {
      List tasksToUpdate = new List();
      // Collect all the Primary Contacts with a non-blank Email
      Set primaryContactIds = new Set();
      for (Contact con : Trigger.new) {
      if (con.Primary_contact__c && !String.isBlank(con.Email)) {
      primaryContactIds.add(con.Id);
      }
      }
      // Retrieve the related Tasks with the existing Email__c field
      List existingTasks = [SELECT Id, Email__c FROM Task WHERE WhoId IN :primaryContactIds];
      // Update the Email__c field on the existing Tasks
      for (Task tsk : existingTasks) {
      tsk.Email__c = Trigger.newMap.get(tsk.WhoId).Email;
      tasksToUpdate.add(tsk);
      }
      // Perform the update on the affected Tasks
      if (!tasksToUpdate.isEmpty()) {
      update tasksToUpdate;
      }
      }

  • @deepanshusaini665
    @deepanshusaini665 ปีที่แล้ว +1

    Hey,
    can you please provide link for following code.. also for complete Trigger scenario series..
    it will be very helpful for me..

    • @sfdcninjas
      @sfdcninjas  ปีที่แล้ว

      Hi Deepanshu it will be available very soon don’t worry

  • @goldylodhi2116
    @goldylodhi2116 ปีที่แล้ว +1