• Talant
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
@isTest
public class PropRentTotalSumTEST {
    @isTest
    static void testFeeCalculation() {



        Property__c prop = new Property__c();
        prop.Name = 'Test';
        prop.Monthly_Rate__c = 0;

        insert prop;

        List<Fee__c> fees = new List<Fee__c>();
        Fee__c fees1=new Fee__c();
        fees1.Name = 'Realtor';
        fees1.Cost__c = 1000;
        fees1.Property__c = prop.Id;

        Fee__c fees2=new Fee__c();
        fees2.Name = 'Lawyer';
        fees2.Cost__c = 2000;
        fees2.Property__c = prop.Id;
        fees.add(fees1);
        fees.add(fees2);

        Test.startTest();

    insert fees;
    delete fees;

        Test.stopTest();

    Property__c propsProperty = [SELECT Monthly_Rate__c FROM Property__c WHERE Id =: prop.Id];

        System.assertEquals(0, propsProperty.Monthly_Rate__c);

    }
}

 
  • April 03, 2020
  • Like
  • 0
public with sharing class PropRentTotalSum {
public static void RentTotal(List<Fee__c> fees) {
List<Id> ids = new List<Id>(); List<Property__c> properties = new List<Property__c>();
for (Fee__c fee : fees) { ids.add(fee.Property__c); }
for (Property__c p : [ SELECT Id,Monthly_Rate__c, (SELECT Id, Cost__c FROM Fees__r) FROM Property__c WHERE Id = :ids ]) { Decimal sum = 0;
for (Fee__c fee : p.Fees__r) { sum = sum + fee.Cost__c; } p.Monthly_Rate__c = sum; properties.add(p); }
try { update properties ; }
catch (Exception e) {
System.debug('Exception :' + e.getMessage());
} } }
  • April 01, 2020
  • Like
  • 0
@isTest
public class PropRentTotalSumTEST {
    @isTest
    static void testFeeCalculation() {



        Property__c prop = new Property__c();
        prop.Name = 'Test';
        prop.Monthly_Rate__c = 0;

        insert prop;

        List<Fee__c> fees = new List<Fee__c>();
        Fee__c fees1=new Fee__c();
        fees1.Name = 'Realtor';
        fees1.Cost__c = 1000;
        fees1.Property__c = prop.Id;

        Fee__c fees2=new Fee__c();
        fees2.Name = 'Lawyer';
        fees2.Cost__c = 2000;
        fees2.Property__c = prop.Id;
        fees.add(fees1);
        fees.add(fees2);

        Test.startTest();

    insert fees;
    delete fees;

        Test.stopTest();

    Property__c propsProperty = [SELECT Monthly_Rate__c FROM Property__c WHERE Id =: prop.Id];

        System.assertEquals(0, propsProperty.Monthly_Rate__c);

    }
}

 
  • April 03, 2020
  • Like
  • 0
public with sharing class PropRentTotalSum {
public static void RentTotal(List<Fee__c> fees) {
List<Id> ids = new List<Id>(); List<Property__c> properties = new List<Property__c>();
for (Fee__c fee : fees) { ids.add(fee.Property__c); }
for (Property__c p : [ SELECT Id,Monthly_Rate__c, (SELECT Id, Cost__c FROM Fees__r) FROM Property__c WHERE Id = :ids ]) { Decimal sum = 0;
for (Fee__c fee : p.Fees__r) { sum = sum + fee.Cost__c; } p.Monthly_Rate__c = sum; properties.add(p); }
try { update properties ; }
catch (Exception e) {
System.debug('Exception :' + e.getMessage());
} } }
  • April 01, 2020
  • Like
  • 0