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 8 years 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

    Why Get Your Business Started with Salesforce Sustainability Cloud?

    Blog in Salesforce

    Salesforce Sustainability Cloud is a powerful platform designed to help companies track, analyze, and report on their sustainability performance. The tool provides a comprehensive set…

    Apps, Benefits, Carbon Footprint, Cloud-based, Companies
    Apphienz Apr 24, 2023
    1,595  Views
    Learn Salesforce Einstein – Chapter 7 (What is Training in Machine Learning-)

    Learn Salesforce Einstein – Chapter 7 (What is Training in Machine Learning?)

    Blog in AI and ML, Salesforce Einstein

    Training a process where we create a model using our datasets. Every prediction query goes to Model, not to the dataset. Let's assume we have…

    Learn Einstein, Salesforce Einstein, Salesforce Einstein Language
    0to1Code.Com Sep 19, 2017
    6,488  Views

    Salesforce Year 2021 Highlights

    Blog in Salesforce

    As we come to a year-end, we cannot wrap up the year without acknowledging all the significant and game-changing work Salesforce has done in the…

    AWS Cloud, B2B Marketing Automation Platforms, Businesses, CRM, Customers
    Apphienz Jan 20, 2022
    2,158  Views

    Popular Salesforce Videos

    What is Approval Process in Salesforce?

    What is Approval Process in Salesforce?

    Video in Salesforce Admin

    Automated process that approves records for the organization and it can be defined with a sequence of steps. Watch the video to learn and if…

    Salesforce Training, Salesforce Online Training, Salesforce Objects, Salesforce Org, Salesforce Approval process
    CRS May 4, 2022
    1,773  Views
    Deleting Contacts in Salesforce Marketing Cloud

    Deleting Contacts in Salesforce Marketing Cloud

    Video in

    Delete contacts to remove contact information from your Marketing Cloud Contact Builder account. Delete contact information to meet data compliance regulations. In this episode, Eliot…

    Salesforce Training, salesforce, Salesforce Marketing Cloud, Salesforce Video, Salesforce Learning
    Jogender Oct 15, 2020
    2,405  Views
    Deep Dive into Salesforce Connected App

    Deep Dive into Salesforce Connected App

    Video in Salesforce Training

    In this session, we will deep dive into Salesforce Connected app, its usage for Salesforce developers and admins, various options and configurations provided for Authentication…

    Salesforce Training, Salesforce Tutorial, Salesforce Administrator, Salesforce Admins, Salesforce Developers
    Pooja Sep 3, 2021
    2,006  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

    © 2026 - 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.