Monday, 4 December 2017

AggregateResult in Salesforce Map

AggregateResult in Salesforce is used to find Sum, Min, Max and Avg. It is similar to Aggregate function in SQL.

Using Aggregate Result, we cannot fetch data. It is mainly used to find Sum, Min, Max and Avg.


Code:

List<Interaction__c> InteractionsList = [select id, name, Start_Date__c,
                   CreatedDate from Interaction__c ];

For( Interaction__c int1 : InteractionsList ){
            InteractioUniqueIds.add(int1.id);
 }

List<AggregateResult> IntExpenseList = [select Interaction__c, sum(Amount__c)
                                      from Expense__c
                                     where Spend_Type__c = 'Honoraria' AND Interaction__c
                                     IN: InteractioUniqueIds group by Interaction__c ];



Map<id,Decimal > ExpAmtMap = new Map<id,Decimal >();
     
for(AggregateResult exp: IntExpenseList){
    ExpAmtMap.put((Id)exp.get('Interaction__c'), (Decimal)exp.get('expr0'));
}

wrp is wrapper class:
wrp.ExpensesAmount = ExpAmtMap.get(Interaction.id);

Thursday, 6 July 2017

Multiselect Picklist value inside formula feild


For a multiselect pickfeild to display inside the formula feild use INCLUDES

IF( INCLUDES(Multi_Select_PicklistFeild, 'String to Compare'),'1','-' )


Use ISPICKVAl for single picklist feild
  • ISPICKVAL—Compares the value of a picklist to a single value.
  • CASE—Compares the value of a picklist to multiple values.
  • TEXT—Converts a picklist value into a text value so that you can work with the value in functions that support text value, such as CONTAINS. (Available in only flow formula resources, formula fields, validation rules, and workflow field updates.)