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

    Salesforce Partner Learning Camp

    Salesforce Partner Learning Camp: A Trailhead for Partners?

    Blog in Salesforce, Salesforce Ecosystem

    Created exclusively for Salesforce partners, Salesforce Partner Learning Camp (PLC) is the primary educational resource for building service capabilities to meet customer demands. After Salesforce…

    B2B and B2C Space, Certification Vouchers, Consulting Partners, CPQ, Credential Tracker
    Algoworks May 13, 2021
    3,641  Views
    Einstein Bot

    Learn How to Set Up an Einstein Bot in Salesforce

    Blog in Others, Salesforce Einstein

    If you want to set up the Einstein bot, first you have to connect chat implementation or message channel. For chat implementation, you must check…

    Automated Invitations, Channel Implementation, Chat Agent Configurations, Chat Deployment, Chat Implementation
    Shweta Apr 14, 2021
    17,489  Views
    What is Artificial Intelligence & Machine Learning

    What is AI and Machine Learning?

    Blog in AI and ML

    Hey gyus how are yuo? I think you all are able to read the above line. Few words are incorrect but still you able to…

    Artificial Intelligence, Machine Learning
    0to1Code.Com Aug 18, 2017
    8,921  Views

    Popular Salesforce Videos

    Build a Simple Screen Flow with Salesforce Flow Builder

    Build a Simple Screen Flow with Salesforce Flow Builder

    Video in Others, Salesforce Stories, Salesforce Training

    Did you know that you can build interactive custom components without any code? Flow Builder is a powerful tool for automation and for giving Admins…

    Salesforce Training, Salesforce Flow, Salesforce Admin, Salesforce Video, Admins
    Nauman Jun 16, 2020
    1,877  Views
    Web to Case Functionality in Salesforce | All You Need to Know

    Web to Case Functionality in Salesforce | All You Need to Know

    Video in

    This video discusses the functionality of Web to Case in Salesforce, which allows website users to submit inquiries or information that can be converted into…

    Email Templates, salesforce, Customers, Case, Limitations
    Pooja Apr 18, 2023
    1,195  Views
    Apex Performance Tips and Tricks | Salesforce Video Guide

    Apex Performance Tips and Tricks | Salesforce Video Guide

    Video in Salesforce Apex

    Watch this video to learn all about Apex Performance: • What do we mean by performance? • How do we measure performance? • Loop Performance…

    Salesforce Training, Salesforce Tutorial, Salesforce Apex, SOQL, Salesforce Video
    Jogender May 17, 2021
    1,790  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.