• Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce Consultants
      • Marketing Cloud Consultants
      • Service Cloud Consultants
      • Experience Cloud Consultants
      • Analytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud Consultants
      • Financial Service Cloud Consultants
      • Health Cloud Consultants
      • Commerce Cloud Consultants
      • Manufacturing Cloud Consultants
  • Jobs
  • Marketplace
  • Stories
  • Top Bloggers 2022
  • Advertise With Us
  • Quizzes
  • Discussions
  • Groups
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce Consultants
        • Marketing Cloud Consultants
        • Service Cloud Consultants
        • Experience Cloud Consultants
        • Analytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud Consultants
        • Financial Service Cloud Consultants
        • Health Cloud Consultants
        • Commerce Cloud Consultants
        • Manufacturing Cloud Consultants
    • Jobs
    • Marketplace
    • Stories
    • Top Bloggers 2022
    • Advertise With Us
    • Quizzes
    • Discussions
    • Groups

    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 5 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

    Reply

    Subscribe

    airslate

    SALESFORCE PRODUCT EXPERTISE

    • Top Salesforce Consultants
    • Top Salesforce Experience Cloud Consultants
    • Top Salesforce Analytics Cloud Consultants
    • Top Salesforce Service Cloud Consultants
    • Top Salesforce Marketing Cloud Consultants

    SALESFORCE INDUSTRY EXPERTISE

    • Top Salesforce Consultants
    • Top Salesforce Manufacturing Cloud Consultants
    • Top Salesforce Non-Profit Cloud Consultants
    • Top Salesforce Health Cloud Consultants
    • Top Salesforce Financial Service Cloud Consultants
    • Top Salesforce Commerce Cloud Consultants

    Popular Salesforce Blogs

    Salesforce Data Extensions

    Landing Page Login Form And Save Data In Salesforce Data Extensions

    Blog in Data, Salesforce, Salesforce Apex

    As all we know, Salesforce Marketing Cloud is a tool that provides digital marketing automation and services and analytics software. And Landing page is an…

    AMPScript, Ampscript Guide, Analytics Software, Data extensions, Email Studio
    Manish May 19, 2020
    7,509  Views
    Salesforce Winter '23 Analytics

    A Deep Dive Into Salesforce Winter '23 Analytics Updates

    Blog in Salesforce Releases

    In this blog, we take a look at the new features and updates to Salesforce Analytics from the Winter '23 release. Custom Report Types As…

    Analytics Side of Salesforce, App Templates, Composite Fields, Connections, Create a New Report
    Stimulus Consulting Dec 8, 2022
    901  Views
    salesforce data

    Displaying data from the related Supplier__c records on a Visualforce page that has a custom controller for the Buyer__c object

    Blog in Salesforce Certifications

    How can a developer display data from the related Supplier__c records on a Visualforce page that has a custom controller for the Buyer__c object? The…

    Apex, Apex Controller, Apex Extension, Buyer__c Object, Custom Controller
    Parikshit Jul 27, 2020
    6,162  Views

    Popular Salesforce Videos

    How To Create A Case Assignment Rule In Salesforce

    How To Create A Case Assignment Rule In Salesforce

    Video in Salesforce Training

    Learn all about how to create Case Assignment rules. In this video, the following points will be covered - 1. Introduction To Case Assignment Rule…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Algoworks Oct 4, 2021
    1,191  Views
    Building a Custom UI with Lightning Web Components | Salesforce Tutorial

    Building a Custom UI with Lightning Web Components | Salesforce Tutorial

    Video in Lightning, Salesforce Training

    Lightning Web Components is a modern JavaScript framework that leverages the web standards breakthroughs over the past few years. Watch this session to understand how…

    Salesforce Training, Salesforce Tutorial, salesforce platform, UI, Salesforce Video
    Rupal Kakkar Apr 29, 2021
    1,360  Views
    How To Use Data Loader In Salesforce - Learn Salesforce Series By Algoworks

    How To Use Data Loader In Salesforce - Learn Salesforce Series By Algoworks

    Video in Salesforce Products, Salesforce Training

    Learn how to use Data Loader in Salesforce. In this video, the following points will be covered - 1. Introduction Here you will get a…

    salesforce, Testing, support, Data Loader, Salesforce Series
    Algoworks Aug 31, 2020
    667  Views
    Footer Forcetalks logo

    [email protected]

    Forcetalks Android App
    Forcetalks IOS App

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2022

    Top Salesforce® Bloggers 2021

    Tips to choose Best Salesforce® Consulting Company

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    Submissions

    Write a Blog

    Start a New Discussion

    Post a Video

    Post an Infographic

    © 2023 - 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®.

    Forum Description

    Report

    There was a problem reporting this post.

    Harassment or bullying behavior
    Harassment or bullying behavior
    Contains mature or sensitive content
    Contains misleading or false information
    Mobile App Reported Contents
    Contains abusive or derogatory content
    Contains spam, fake content or potential malware

    Block Member?

    Please confirm you want to block this member.

    You will no longer be able to:

    • See blocked member's posts
    • Mention this member in posts
    • Invite this member to groups
    • Message this member
    • Add this member as a connection

    Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.

    Report

    You have already reported this .
    Clear Clear All
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.