• Jasjeet Grewal
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi,

I have two objects Account, and abc_and_sale_summary__c. I am trying to implement before update trigger on Account which will update values in abc_and_sale_summary__c.

Account has fields club__c(text), created_date__c, and down_payment__c(text later converted to decimal).
abc_and_sale_summary__c has fields ABC_Down_payment__c, club__c, and date__c.

My trigger on account will update down_payment__c field with value from down_payment__c field.

for example: Account A for club vancouver, date mar 07 has down_payment__c of $100.
Account B for club vancouver, date mar 07 has down_payment__c of $50.
Account C for club vancouver, date mar 07 has down_payment__c of $150.

Trigger will update existing record in abc_and_sale_summary__c for club vancouver and date mar 07. Value of ABC_Down_payment__c should be $300.


Code of update trigger. Right now, it is not updating the ABC_Down_payment__c field. Please help me point out the problem in logic.
List<ABC_and_Sale_Summary__c> abc= New List<ABC_and_Sale_Summary__c>();
    Map<Id, ABC_and_Sale_Summary__c> abcMap= New Map<Id, ABC_and_Sale_Summary__c>();

if(Trigger.isUpdate ){
        ABC_and_Sale_Summary__c abc2= New ABC_and_Sale_Summary__c();
        List<ABC_and_Sale_Summary__c> abc3= New List<ABC_and_Sale_Summary__c>();
        
        abc3 = [Select id, club__c, date__c, sale_Summary_Revenue__c, ABC_Down_payment__c from ABC_and_Sale_Summary__c];

        for(ABC_and_Sale_Summary__c abc_sale: abc3){

        for(integer c = 0; c < Trigger.Old.size(); c++){
            Date d = date.newinstance(Trigger.New[c].created_date__c.year(), Trigger.New[c].created_date__c.month(), Trigger.New[c].created_date__c.day());
	    	Date d2 = date.newinstance(Trigger.Old[c].created_date__c.year(), Trigger.Old[c].created_date__c.month(), Trigger.Old[c].created_date__c.day());
			
            
                if((abc_sale.club__c == Trigger.Old[c].club__c) && (abc_sale.date__c == d2))
				{
                    system.debug(abc_sale.Id);
					String dp = Trigger.New[c].Down_Payment__c;
            
					if(dp.contains('$')){
						dp = dp.substring(1);
					}
					
					Double downpayment = Decimal.valueOf(dp);
            
					
						String dpold = Trigger.Old[c].Down_Payment__c;
						if(dpold.contains('$')){
							dpold = dpold.substring(1);
						}
						
						Double downpaymentold = Decimal.valueOf(dpold);
						
						double diff = downpayment - downpaymentold;
                    	if(abc_sale.ABC_Down_payment__c ==null){abc_sale.ABC_Down_payment__c = 0;}
						abc_sale.ABC_Down_payment__c = abc_sale.ABC_Down_payment__c + diff;
						
						abc.add(abc_sale);
                        
				}	
			}	
        }
        abcMap.putAll(abc);
            update abcMap.values();
    }

this code is working for single insert/update of record. But, it is not working in case of mass upsert.
Hi all,

I have two objects Account and Sales. Account has fields created date, location, down payment received. Sales has fields date, location, total revenue.

What i am trying to do is to compare sum(down payment received) group by created date and location with total revenue from sales object.

I have made couple of queries wriiten below. I want to use these queries for wrapper class. My main concern now is somehow I want to link both these queries together, so I can view it as table on vf page. 
 
From Account: 
select sum(down_payment_received__c) from account where created_date__c > 2018-03-12T00:00:00Z and created_date__c < 2018-03-13T00:00:00Z and Location__c in ('Location A', 'Location B', 'Location C', 'Location D') group by Location__c


This query will give me result for Mar 12 and for all Locations. 

Similarly, For Sales object:
1select Date__c, Location__c, Total_Revenue_End_of_the_day__c from sales__c where Date__c = 2018-03-12

This query will give results for sales object. 

But, what I wanted is use a single query to get results from both objects.

I would like a data such as following (layout could be little different)

Date                     Location            Down Payment            Total Revenue             Total Revenue - Down Payment
2018-03-18           Location A                 100                              100                                           0
2018-03-18           Location B                 150                              100                                          50


Please, let me know how this could be possible. 
Hi everyone,

I have two objects Account and Sales.
Account has fields - name, created date, location, payment made.
Sales has fields - date, location, revenue.

I want to compare sum of all payment made by all accounts group by created date and location with revenue from sales object on particular date for same location.
 
for eg: 5 accounts from location A on Mar 01 has sum of 1000 as payment made.
Also on sales object location A on mar 01 should have revenue greater than 1000 or more.

I have tried reports, but I am not successful in getting it solved.

please suggest me possible ideas which I can use to implement this. I am comfortable using apex if needed.
Hi all,

I have two objects Account and Sales. Account has fields created date, location, down payment received. Sales has fields date, location, total revenue.

What i am trying to do is to compare sum(down payment received) group by created date and location with total revenue from sales object.

I have made couple of queries wriiten below. I want to use these queries for wrapper class. My main concern now is somehow I want to link both these queries together, so I can view it as table on vf page. 
 
From Account: 
select sum(down_payment_received__c) from account where created_date__c > 2018-03-12T00:00:00Z and created_date__c < 2018-03-13T00:00:00Z and Location__c in ('Location A', 'Location B', 'Location C', 'Location D') group by Location__c


This query will give me result for Mar 12 and for all Locations. 

Similarly, For Sales object:
1select Date__c, Location__c, Total_Revenue_End_of_the_day__c from sales__c where Date__c = 2018-03-12

This query will give results for sales object. 

But, what I wanted is use a single query to get results from both objects.

I would like a data such as following (layout could be little different)

Date                     Location            Down Payment            Total Revenue             Total Revenue - Down Payment
2018-03-18           Location A                 100                              100                                           0
2018-03-18           Location B                 150                              100                                          50


Please, let me know how this could be possible. 
Hi everyone,

I have two objects Account and Sales.
Account has fields - name, created date, location, payment made.
Sales has fields - date, location, revenue.

I want to compare sum of all payment made by all accounts group by created date and location with revenue from sales object on particular date for same location.
 
for eg: 5 accounts from location A on Mar 01 has sum of 1000 as payment made.
Also on sales object location A on mar 01 should have revenue greater than 1000 or more.

I have tried reports, but I am not successful in getting it solved.

please suggest me possible ideas which I can use to implement this. I am comfortable using apex if needed.