Trigger scenario(when account address is updated related contact address also updates)

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 เม.ย. 2020
  • HI,everyone
    here you are going to learn about Trigger scenario(when account address is updated related contact address also updates)
    this is the most asked question in interview
    so like share and subscribe and don't forget to hit that bell icon
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @pampariabhiram01
    @pampariabhiram01 3 ปีที่แล้ว +3

    Thanks for your scenario...In my working environment I got a similar kind of requirement I did it in a different way but coming to test class it's not working. Based on your video I completed the task successfully with 100% coverage....Thanks for you & your video.

  • @balajiprakasam
    @balajiprakasam 4 ปีที่แล้ว +3

    Well done

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

    Do subscribe the channel so u will get the notification of upcoming videos

  • @AmanMishra-qe1bv
    @AmanMishra-qe1bv 2 ปีที่แล้ว

    Awsm❤️

  • @kamleshgajbhiye4179
    @kamleshgajbhiye4179 3 ปีที่แล้ว +2

    Thanks for the video

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

    I think this can be done in a single for loop using Trigger.newMap -> Query all contacts where AccountId in Trigger.newMap.keySet() -> iterate on contacts { get the account sobject using contact.AccountId and trigger.newMap -> update the contact address info -> add contact to a list -> update DML after the loop. Also instead of hardcoding fields like MailingAddress and BillingAddress we can also a custom metadata type or custom setting to save the account to contact mapping so that in future if there are more fields to map we don't have to update the trigger every time.
    Hope this helps! thanks!
    Sample Code -
    trigger AccountTrigger on Account(after update){
    try{
    List listToUpdate = new List();

    Map accountMap = trigger.newMap;
    List relatedContactList = [SELECT Id,AccountId From Contact WHERE AccountId in :accountMap.keySet());
    List accountContactMappingList = getAccountContactMapping();
    for(Contact relatedContact : relatedContactList){
    Id accountId = relatedContact.AccountId;
    Account acc = accountMap.get(accountId);
    if(acc != null){
    for(AccountContactMapping__mdt accConMapping : accountContactMappingList){
    String accountFieldApiName = accConMapping.AccountFieldApiName__c;
    String contactFieldApiName = accConMapping.ContactFieldApiName__c;
    con.put(contactFieldApiName,account.get(accountFieldApiName));
    }
    listToUpdate.add(con);
    }
    }

    if(!listToUpdate.isEmpty()){
    update listToUpdate;
    }
    }catch (Exception e){
    System.debug('e.getMessage()------>>>'+e.getMessage());
    System.debug('e.getStackTraceString()------>>>'+e.getStackTraceString());
    //Make an entry to an object called ErrorLog__c //Logger.logException('AccountTrigger','updateRelatedContacts',e.getMessage(),e.getStackTraceString(),System.now(),userInfo.getUserId());
    }
    }
    static List getAccountContactMapping(){
    if(!Test.isRunningTest()){
    return AccountContactMapping__mdt.getAll().values();
    }else{
    return List{new AccountContactMapping__mdt(AccountFieldApiName__c='Billing Address',ContactFieldApiName__c='BillingAddress')}
    }
    }

  • @chithraprakash8392
    @chithraprakash8392 2 ปีที่แล้ว

    Thank you for a very useful video

  • @vishaladane8153
    @vishaladane8153 2 ปีที่แล้ว

    great

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

    Thanks ma'am

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

    Hi Yamini,
    I have Query like How many times gets changed in billing address it will store in account object one custom field.

  • @arun6479
    @arun6479 2 ปีที่แล้ว

    Hello! explanation was absolutely great 👍 thank you...
    Could you please be little better louder ...

  • @chithraprakash8392
    @chithraprakash8392 2 ปีที่แล้ว

    Can you upload more videos on trigger for different scenarios

  • @kartheeksreddy7116
    @kartheeksreddy7116 2 ปีที่แล้ว +2

    Hi ua trigger is working fine but writing for loop inside the for loop is not a best practice right

    • @dharmendrayadav-cn2fi
      @dharmendrayadav-cn2fi 2 ปีที่แล้ว

      Yes, for look inside for loop cause recursion in trigger

  • @PlayfulPixelsTV107
    @PlayfulPixelsTV107 3 ปีที่แล้ว

    My client in USA and I am India my currecy symbol change how to automate dollar symbol send that time

  • @srisadgurusairam1688
    @srisadgurusairam1688 2 ปีที่แล้ว

    How to write test class for this trigger?

  • @PlayfulPixelsTV107
    @PlayfulPixelsTV107 3 ปีที่แล้ว

    Doubt doubt

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

    Why do we need to fetch the deleted contacts here

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

    mam plz explain with handler class also

    • @Srinud-ux4ew
      @Srinud-ux4ew 2 ปีที่แล้ว

      Similer same..but in method we take parameters as list aclist ..then logic..same..
      After in trigger calling handler method with (trigger.new)

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

    voice is very slow.

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

    Do you think it will work ?you didnt include the condition to check whether the address field has updated

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

      Yes i was also thinking about the same