Apex Triggers - 43 (Infosys Interview Scenario)

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ต.ค. 2024

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

  • @goldylodhi2116
    @goldylodhi2116 9 หลายเดือนก่อน +1

    Great explanation ❤

  • @arunimakashyap6207
    @arunimakashyap6207 9 หลายเดือนก่อน +1

    Nice video

    • @sfdcninjas
      @sfdcninjas  9 หลายเดือนก่อน

      Thanks

  • @kumareshghosh5593
    @kumareshghosh5593 9 หลายเดือนก่อน +1

    Hi Bro,
    Thank you soo much for lots of trigger scenairos what I practise on daily basis and becoming a pro in this, I have been commening on your videos since very long with my personalised code, would be great if you review those and provide certain feedbacks which will encourage me as well.

  • @prashantgpt1990
    @prashantgpt1990 7 หลายเดือนก่อน

    Hello dear
    In the trigger handler class there is requirement like where we have to use so many soql queries and we make it asynchronous and use future method for this.
    But still so much queries are used so for avoid limit exception what is the best solution.

  • @chandudevtech
    @chandudevtech 9 หลายเดือนก่อน

    Today I attend TCS walkin. Scenario " I have account and it's have one check box field. If it's checked only one contact should be associated. If try to create another contact... Primary contact and account owner should be notified as 'some one inserting contact ', and user should get error like already account related primary contact is there so you can't create contact.
    Trigger scenario. Please provide me code.

    • @hekkelkelseheklalallkh8161
      @hekkelkelseheklalallkh8161 7 หลายเดือนก่อน

      public class Only_One_Contact_Checked_Account
      {

      public static void TriggerExecute(list ccList, map oldmap)
      {
      List lstEmailAlerts = new List();
      set accids = new set();
      if(! ccList.isEmpty())
      {
      for(contact cc : ccList)
      {
      if(oldmap != Null)
      {
      contact oldcc = oldmap.get(cc.Id);
      if(oldcc.AccountId != cc.AccountId)
      {
      accids.add(cc.AccountId);
      }
      }
      else if(cc.AccountId != Null)
      {
      accids.add(cc.AccountId);
      }
      }
      }
      if(! accids.isEmpty())
      {
      map mapacc = new map([select id, name, Owner.email, Only_One_Contact__c
      from Account WHERE id in: accids and Only_One_Contact__c = true]);
      map Contacts_for_Account = new map();
      for(account acc : mapacc.values())
      {
      Contacts_for_Account.put(acc.Id, new Contact());
      }
      for(Contact cc : [select id, AccountId, Email from Contact WHERE AccountId in: accids])
      {
      Contacts_for_Account.put(cc.AccountId , cc);
      }
      for(contact cc: ccList)
      {
      if(Contacts_for_Account.containsKey(cc.AccountId) && Contacts_for_Account.get(cc.AccountId) != Null)
      {
      Messaging.SingleEmailMessage sEmail = new Messaging.SingleEmailMessage();

      String[] toAddress = new String[]{mapacc.get(cc.AccountId).Owner.Email};
      sEmail.setToAddresses(toAddress);

      sEmail.setSenderDisplayName('Salesforce Error Notification');

      sEmail.setReplyTo(mapacc.get(cc.AccountId).Owner.Email);

      String emailSubject = 'Error Occurred' ;
      sEmail.setSubject(emailSubject);
      String emailbody = 'Someone with the username ' + UserInfo.getUserName()+ ' is trying to Insert additional contact for your only one contact Account with Name' + mapacc.get(cc.AccountId).Name;
      sEmail.setHtmlBody(emailbody);
      lstEmailAlerts.add(sEmail);
      cc.addError('The Account should have only one Contact, which is already present');
      }
      }
      if(! lstEmailAlerts.isEmpty())
      {
      Messaging.SendEmailResult[] results = Messaging.sendEmail(lstEmailAlerts);
      }
      }
      }
      },
      Trigger :
      trigger Only_One_Contact on Contact (before insert, before update)
      {
      if(trigger.isInsert && trigger.isBefore)
      {
      Only_One_Contact_Checked_Account.TriggerExecute(trigger.new, Null);
      }
      if(trigger.isUpdate && trigger.isBefore)
      {
      Only_One_Contact_Checked_Account.TriggerExecute(trigger.new, trigger.oldMap);
      }
      }
      Hi, can you check if the above code matches to your Scenario......and send any necessary corrections

  • @anubhavsingh8144
    @anubhavsingh8144 9 หลายเดือนก่อน +1

    hello buddy
    could you please make the video on below mentioned scnerio
    write a trigger when case is created and has email in SuppliedEmail field check if the same email is present in the email field of your any contact tag that case to contact else create new contact and tag case to it.
    I lately attended infy interview where i got it, after writing code interview said this way you will get read only error.
    Please make a video on it, would be helpful for all of us.

    • @sfdcninjas
      @sfdcninjas  9 หลายเดือนก่อน +2

      Sure buddy i will try to create a video asap, don’t worry

    • @sravanigosula545
      @sravanigosula545 9 หลายเดือนก่อน

      Hi, tomorrow I have Infosys interview can u plz tell me what questions they have asked u

    • @hekkelkelseheklalallkh8161
      @hekkelkelseheklalallkh8161 7 หลายเดือนก่อน

      Hi for what field did he say that you will get readonly error, and can you share the code if you have completed the scenario