• Kuliza Dev
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Reports = [select Id, Name from Report where Format = 'Tabular' order by Name];
          for(Report report : Reports)
          {
              ReportModel rm = new ReportModel();
              rm.ReportId = (string)report.get('Id');
              rm.ReportName = (string)report.get('Name');
              options.Add(rm);
          }
I'm trying to fetch the number of records in each Report. I tried using getRecords() but it is saying invalid function. I am flexible to implement this through Apex or SOQL. 
Hi All,

I have created a custom Lead Page using visualforce page. I am successfully able to integrate with the Lead control and use the tabStyle as Lead. Now I also want to show the activity history of the Lead in my custom page. Is there a way of doing this ? 

Please let me know if my question is not clear or any of you need any more update ?

Thanks in advance
Hi 
I am facing below error for my trigger 
SF error "Too many SOQL queries: 101"

Below are my trigger and class 

trigger :

trigger rollUpTasks on Task (after delete, after insert,
after undelete) {
//if the task is an insert, update, or undelete
if(trigger.isInsert || trigger.isUnDelete){
for(Task t :Trigger.new){
//if the task is on a Lead

if(t.WhoId != null && String.valueof(t.WhoId).startsWith('00Q')){

list<RollUpSummaryUtility.fieldDefinition> activityDefinitions = new list<RollUpSummaryUtility.fieldDefinition> {

new RollUpSummaryUtility.fieldDefinition('COUNT', 'ID', 'Total_Num_of_Activities__c')
};

RollUpSummaryUtility.rollUpTrigger(activityDefinitions, trigger.new,

'Task', 'WhoID', 'Lead', 'and IsClosed = True ');
}
//if task is on a Contact
if(t.WhoId != null && String.valueof(t.WhoId).startsWith('003')){

list<RollUpSummaryUtility.fieldDefinition> activityDefinitions =
new list<RollUpSummaryUtility.fieldDefinition> {
new RollUpSummaryUtility.fieldDefinition('COUNT', 'ID', 'Total_Num_of_Activities__c')

};

RollUpSummaryUtility.rollUpTrigger(activityDefinitions, trigger.new,
'Task', 'WhoID', 'Contact', 'and IsClosed = True ');

}
}
}

//if the task is a delete
if(trigger.isDelete){
for(Task t :Trigger.old){
//if the task is on a Lead
if(t.WhoId != null && String.valueof(t.WhoId).startsWith('00Q')){

list<RollUpSummaryUtility.fieldDefinition> activityDefinitions = new list<RollUpSummaryUtility.fieldDefinition> {
new RollUpSummaryUtility.fieldDefinition('COUNT', 'ID', 'Total_Num_of_Activities__c')

};

RollUpSummaryUtility.rollUpTrigger(activityDefinitions, trigger.old,
'Task', 'WhoID', 'Lead', 'and IsClosed = True');
 
}
//if task is on a Contact
if(t.WhoId != null && String.valueof(t.WhoId).startsWith('003')){
list<RollUpSummaryUtility.fieldDefinition> activityDefinitions =

new list<RollUpSummaryUtility.fieldDefinition> {
new RollUpSummaryUtility.fieldDefinition('COUNT', 'ID', 'Total_Num_of_Activities__c')
};
 
RollUpSummaryUtility.rollUpTrigger(activityDefinitions, trigger.old,
'Task', 'WhoID', 'Contact', 'and IsClosed = True ');
}

}

}
}

Class :

RollUpSummaryUtility class:
public class RollUpSummaryUtility {

//the following class will be used to house the field names
//and desired operations
public class fieldDefinition {
public String operation {get;set;}


public String childField {get;set;}
public String parentField {get;set;}

public fieldDefinition (String o, String c, String p) {
operation = o;
childField = c;
parentField = p;
}
}

public static void rollUpTrigger(list<fieldDefinition> fieldDefinitions,
list<sObject> records, String childObject, String childParentLookupField,


String parentObject, String queryFilter) {

//Limit the size of list by using Sets which do not contain duplicate
//elements prevents hitting governor limits
set<Id> parentIds = new set<Id>();
for(sObject s : records) {
parentIds.add((Id)s.get(childParentLookupField));
}

//populate query text strings to be used in child aggregrator and

//parent value assignment

String fieldsToAggregate = '';
String parentFields = '';

for(fieldDefinition d : fieldDefinitions) {
fieldsToAggregate += d.operation + '(' + d.childField + ') ' +', ';
parentFields += d.parentField + ', ';
}

//Using dynamic SOQL with aggergate results to populate parentValueMap
String aggregateQuery = 'Select ' + fieldsToAggregate +childParentLookupField + ' from ' + childObject + ' where ' +childParentLookupField + ' IN :parentIds ' + queryFilter + ' ' +' group by ' + childParentLookupField;

//Map will contain one parent record Id per one aggregate object
map<Id, AggregateResult> parentValueMap = new map <Id, AggregateResult>();

for(AggregateResult q : Database.query(aggregateQuery)){
parentValueMap.put((Id)q.get(childParentLookupField), q);
}

//list of parent object records to update
list<sObject> parentsToUpdate = new list<sObject>();



String parentQuery = 'select ' + parentFields + ' Id ' +' from ' + parentObject + ' where Id IN :parentIds';

//for each affected parent object, retrieve aggregate results and


//for each field definition add aggregate value to parent field
for(sObject s : Database.query(parentQuery)) {

Integer row = 0; //row counter reset for every parent record


for(fieldDefinition d : fieldDefinitions) {
String field = 'expr' + row.format();
AggregateResult r = parentValueMap.get(s.Id);
//r will be null if no records exist


//(e.g. last record deleted)
if(r != null) {
Decimal value = ((Decimal)r.get(field) == null ) ? 0 :
(Decimal)r.get(field);
s.put(d.parentField, value);
}
else {
s.put(d.parentField, 0);
}
row += 1; //plus 1 for every field definition after first
}
parentsToUpdate.add(s);


}

//if parent records exist, perform update of all parent records
//with a single DML statement
if(parentsToUpdate.Size() > 0) {
update parentsToUpdate;
}

}

}
Hi All,

I have created a custom Lead Page using visualforce page. I am successfully able to integrate with the Lead control and use the tabStyle as Lead. Now I also want to show the activity history of the Lead in my custom page. Is there a way of doing this ? 

Please let me know if my question is not clear or any of you need any more update ?

Thanks in advance