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, 11 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

    How to Become a Salesforce Developer in 2024?

    Blog in Others, Salesforce, Salesforce Tutorial

    The world of customer relationship management (CRM) is undergoing a revolution, and at the forefront stands Salesforce, the undisputed king of cloud-based CRM solutions. But…

    Cloud Based CRM, Communication, CRM, Customer Experiences, Customer Relationship Management
    William Jan 30, 2024
    1,251  Views

    Convert Accounts and Contacts to Leads Easily With the Blink App

    Blog in Salesforce Admin

    Converting accounts or contacts back to leads in Salesforce can be a challenging process as it goes against the standard Salesforce data model. That’s why ENWAY has…

    App Benefits, App Features, App Installation, AppExchange Marketplace, Attachments
    ENWAY Sep 7, 2023
    1,695  Views

    Salesforce Distributed Marketing – Enabling the last mile to connect!

    Blog in Salesforce Products

    Salesforce Distributed Marketing – When you utter the name of a brand and people are able to instantly recognize, it’s not just because they know…

    Customer Experiences, Features of Marketing Cloud, Marketing Automation, Marketing Campaigns, Sales Cloud
    DemandBlue Jun 10, 2019
    2,400  Views

    Popular Salesforce Videos

    How to Get Experience Without the Job? | Salesforce Learning

    How to Get Experience Without the Job? | Salesforce Learning

    Video in Salesforce Training

    Want to get experience without the job? Watch the full episode here: https://youtu.be/oG8sHOW8GI4 Shrey is a Chief Executive Officer at Cyntexa, a SILVER Salesforce Consulting…

    Salesforce Training, salesforce, Salesforce Hulk, Salesforce Video, Salesforce Learning Courses
    S2 Nov 18, 2021
    2,351  Views
    SelectList, select Option & Action Function in Salesforce Apex Language

    SelectList, select Option & Action Function in Salesforce Apex Language

    Video in Visualforce, Salesforce Apex

    If you work upon salesforce and VF Pages, you have seen these words one is rendered, reRender, ActionFunction, param, onclick, onchange, In this video, you…

    Apex APIs, Apex, Salesforce Objects, How To Learn Apex, Salesforce Apex Tutorial
    Pooja Nov 26, 2018
    2,744  Views
    Salesforce Nonprofit Success Pack Implementation Guide

    Salesforce Nonprofit Success Pack Implementation Guide

    Video in Salesforce For Nonprofits

    There are so many things to consider when using Salesforce Nonprofit Success Pack for your nonprofit organization that it can be tricky to know where…

    Salesforce Training, Salesforce Tutorial, Salesforce Development, Salesforce Implementation, salesforce
    DB Aug 23, 2023
    1,181  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.