Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Marketplace
    • Advertise With Us
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › Help me on the given Salesforce Trigger Scenario

    Tagged: Bulk Class, Contact Record, Number Field, Parent Account, Picklist, Salesforce Custom Object, Salesforce Fields, Salesforce Trigger, Salesforce Trigger Condition, Test Class

    • Salesforce® Discussions

      Help me on the given Salesforce Trigger Scenario

      Posted by sajid ali on December 5, 2017 at 1:09 PM

      Scenario 1.

      1) Make two number fields on contact object Amount_X Amount_Y

      2) Make one picklist field "Type" , values ('Positive', 'Negative')

      3) Make two number fields on account Rollup_Amount_X Rollup_Amount_Y Rollup_Amount

      4) Make one trigger on contact object, which will do following: --> Sum all child of contact's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive" --> Sum all child of contact's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative" --> Sum all child of contact's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"

      5) Make trigger as bulk / Test class

      Ashi replied 7 years, 10 months ago 3 Members · 2 Replies
      • Bulk Class
      • Contact Record
      • Number Field
      • Parent Account
      • Picklist
      • Salesforce Custom Object
      • Salesforce Fields
      • Salesforce Trigger
      • Salesforce Trigger Condition
      • Test Class
    • 2 Replies
    • Subhendu

      Member
      January 9, 2018 at 2:16 PM

      Hi Sajid,

      You can have a trigger something like --

      trigger calculateAmount on Contact(after update,after insert){

      set<Id> idList = new set<Id>();
      List<Account> accList = new List<Account>();
      for(Contact con: Trigger.new){

      idList.add(con.AccountId);
      }
      List<Account> accList = [Select Id,Rollup_Amount_X__c,Rollup_Amount_Y__c (Select Id,Amount_X__c, Amount_Y__c, Type__c from Contacts) from Account where Id in:idList];

      for(Account acc: accList){
      Integer amountx=0;
      Integer amounty=0;
      for(Contact con: acc.Contacts){

      if(con.Type__c=='Positive'){
      amountx += con.Amount_X__c;
      }else{

      amounty += con.Amount_Y__c;
      }
      }
      acc.Rollup_Amount_X__c = amountx;
      acc.Rollup_Amount_Y__c = amounty;
      accList.add(acc)
      }

      update accList;
      }

      Hope this helps.

      Thanks,
      Subhendu

    • Ashi

      Member
      January 15, 2018 at 6:39 AM

      Hey sajid,

      trigger sumcontact on Contact (after insert , after update) {
      list<account> updateacc = new list<account>();
      set<id> aid = new set<id>();
      for(contact con : trigger.new)
      {
      aid.add(con.accountid);
      }
      list<account> acclist =[select id , name,Rollup_Amount__c ,(select id, name,Amount_X__c,Type__c ,Amount_Y__c from contacts ), Rollup_Amount_X__c ,Rollup_Amount_Y__c from account where id in : aid];
      for(account acc : acclist)
      {
      decimal amountx =0.0;
      decimal amounty =0.0;
      decimal totalsum ;
      for(contact con:acc.contacts)
      {
      if(con.Type__c == 'positive')
      {
      amountx += con.Amount_X__c;
      acc.Rollup_Amount_X__c = amountx;
      }
      else{
      amounty += con.Amount_Y__c;
      acc.Rollup_Amount_Y__c = amounty;
      }
      }
      totalsum = amountx + amounty ;
      acc.Rollup_Amount__c = totalsum ;
      updateacc.add(acc);
      }
      update updateacc;
      }

      Hope this help for others.

      Thanks

      Ashi

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    application solution

    Popular Salesforce Blogs

    Formula to Get Time Zone Based on Area Code in Salesforce

    Blog in Salesforce Tutorial

    In this article, you will learn to create a formula to get the time zone based on Area Code in the phone number field in…

    Area Code, Data Loader, Field in Salesforce, Formula Code, Salesforce
    Kapil Jun 23, 2020
    13,647  Views

    Questions to Ask Before Hiring the Services of a Salesforce Partner

    Blog in Salesforce Consultant

    To sustain in this era of cutthroat competition, maintaining superior customer relationships has become the need of the hour. This can be possible by providing…

    AppExchange, Business, Business Ecosystem, Business Issues, Consultants
    Girikon May 10, 2022
    2,962  Views

    Read this before you perform your Salesforce Data Migration

    Blog in Salesforce Implementation

    Salesforce Data Migration — Imagine if you were traveling to an exotic new destination for the holidays. You want to make sure that everything is…

    Data Import Wizard, Data Migration, Salesforce Admin, Salesforce Data, Salesforce Data Backup
    DemandBlue Dec 10, 2018
    3,105  Views

    Popular Salesforce Videos

    Creating an Approval Process in Salesforce with Example

    Creating an Approval Process in Salesforce with Example

    Video in Salesforce Implementation

    Approval Process in Salesforce is an automated process that automates how Salesforce records are approved in your org. Approval Process in Salesforce is a combination…

    Salesforce Administration, Salesforce1, Salesforce Records, Email Templates, Salesforce Fields
    Pooja Apr 3, 2018
    3,192  Views
    Integrate Salesforce and Active Directory Step by Step

    Integrate Salesforce and Active Directory Step by Step

    Video in Salesforce Integration

    The prospect of implementing Single Sign-on in your Salesforce org can seem daunting if you are unfamiliar with the process. In this live step-by-step demo…

    Salesforce Integration, Cloud Computing, Enterprise Application Development, Salesforce Org, Salesforce Integration Cloud
    Portia Apr 16, 2018
    1,933  Views
    Happy 2021 to the Salesforce Ohana

    Happy 2021 to the Salesforce Ohana

    Video in Salesforce Stories

    As 2020 comes to a close, the challenges of the past year give way to hopes of a new year full of love, cheer, &…

    Salesforce Community, Salesforce Ohana, Salesforce Guide, Salesforce Video, Salesforce Help
    Pooja Jan 7, 2021
    1,493  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2025 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.