Skip to content

Commit

Permalink
Merge pull request #15 from wes1278/master
Browse files Browse the repository at this point in the history
rollup summary new page v1.0
  • Loading branch information
afawcett committed Apr 8, 2014
2 parents 6215ff5 + b134aaa commit 7ed63d0
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 0 deletions.
162 changes: 162 additions & 0 deletions rolluptool/src/classes/RollupSummary_NewPage_Controller.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
public class RollupSummary_NewPage_Controller {
private ApexPages.StandardController controller {get; set;}
private LookupRollupSummary__c rus;
private Set<String> numeric;
public List<SelectOption> parentObjects {get;set;}
public List<SelectOption> parentFields {
get{
List<SelectOption> retList = new List<SelectOption>();
retList.add(new SelectOption('','Select'+ (String.isBlank(rus.ParentObject__c)?'':' ' +rus.ParentObject__c) + ' field...'));
if(String.isNotBlank(rus.ParentObject__c))
{

Map<String, Schema.SObjectField> parentFieldMap = gd.get(rus.ParentObject__c).getDescribe().fields.getMap();
for(Schema.SObjectField field : parentFieldMap.values())
{
Schema.DescribeFieldResult res = field.getDescribe();
if(res.isAccessible() && res.isUpdateable() && numeric.contains(String.valueOf(res.getType()).trim().toLowercase()))
{
String objLabel = res.getLabel();
String objAPI = res.getName();
retList.add(new SelectOption(objApi,objLabel));
}
}
}
retList.sort();
return retList;
}
set;
}
public List<SelectOption> childObjects {
get{
List<SelectOption> retList = new List<SelectOption>();
retList.add(new SelectOption('','Select a child object.'));
if(String.isNotBlank(rus.ParentObject__c))
{
for(Schema.ChildRelationship rel : gd.get(rus.ParentObject__c).getDescribe().getChildRelationships())
{
Schema.DescribeSObjectResult res = rel.getChildSObject().getDescribe();
if(res.isAccessible() && res.isUpdateable())
{
String objLabel = res.getLabel() + ' (' + rel.getField() +')';
String objAPI = res.getName()+'.'+rel.getField();
retList.add(new SelectOption(objApi,objLabel));
}
}
}
retList.sort();
return retList;
}
set;
}
public List<SelectOption> childFields {
get{
List<SelectOption> retList = new List<SelectOption>();
retList.add(new SelectOption('','Select child field...'));
if(String.isNotBlank(rus.ChildObject__c))
{
String strChildObject = rus.ChildObject__c.substringBefore('.');

Map<String, Schema.SObjectField> parentFieldMap = gd.get(strChildObject).getDescribe().fields.getMap();
for(Schema.SObjectField field : parentFieldMap.values())
{
Schema.DescribeFieldResult res = field.getDescribe();
if(res.isAccessible() && res.isUpdateable() && numeric.contains(String.valueOf(res.getType()).trim().toLowercase()))
{
String objLabel = res.getLabel();
String objAPI = res.getName();
retList.add(new SelectOption(objApi,objLabel));
}
}
}
retList.sort();
return retList;
}
set;
}
private Map<String, Schema.SObjectType> gd;
public RollupSummary_NewPage_Controller(ApexPages.StandardController stdController) {
this.controller = stdController;
this.rus = (LookupRollupSummary__c)controller.getRecord();
gd = Schema.getGlobalDescribe();
numeric = new Set<String>();
numeric.add('currency');
numeric.add('date');
numeric.add('double');
numeric.add('integer');
numeric.add('percent');

// Get the list of creatable,updateable objects.
parentObjects = new List<SelectOption>();
parentObjects.add(new SelectOption('','Select Parent Object'));
for(String obj : gd.keySet())
{
Schema.DescribeSObjectResult res = gd.get(obj).getDescribe();
if(res.isCreateable() && res.isUpdateable())
{
String objLabel = res.getLabel();
String objAPI = res.getName();
parentObjects.add(new SelectOption(objApi,objLabel));
}
}
parentObjects.sort();
}
public void setRelationshipField()
{
rus.RelationshipField__c = (rus!=null && String.isNotBlank(rus.ChildObject__c)?rus.ChildObject__c.substringAfter('.'):'');
}

public PageReference save()
{
rus.ChildObject__c = rus.ChildObject__c.substringBefore('.');
Set<String> childTrigger = new Set<String>();
childTrigger.add(rus.ChildObject__c);
Map<String, ApexTrigger> apexTriggers = new ApexTriggersSelector().selectByName(childTrigger);
String triggerName = RollupSummaries.makeTriggerName(rus);
Database.SaveResult sr;
if((rus.CalculationMode__c == RollupSummaries.CalculationMode.Realtime.name() ||
rus.CalculationMode__c == RollupSummaries.CalculationMode.Scheduled.name()) &&
!apexTriggers.containsKey(triggerName))
{
//we need the trigger to be created so let's create it,
// and then let's set rus.Active__c = true;
//and then insert the rus record.
Boolean triggerWasDeployedSuccessfully = true; // TODO if the trigger deployment was successful
if(triggerWasDeployedSuccessfully)
{
//rus.Active__c = true; //Uncomment once the trigger deploying works.
sr = Database.insert(rus);
}
}
else
{
//rus.Active__c = true; //Uncomment once the trigger deploying works.
sr = Database.insert(rus);
}
PageReference pageRef;
if(sr.isSuccess())
{
pageRef = new PageReference('/' + rus.Id);
pageRef.setRedirect(true);
}
else
{
for(Database.Error err : sr.getErrors())
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,err.getMessage()));
}
}
return pageRef;
}
public void getChildFields(String parentObjectName)
{
Map<SObjectType, Map<String, Schema.SObjectField>> gdFields = new Map<SObjectType, Map<String, Schema.SObjectField>>();
SObjectType parentObjectType = gd.get(rus.ParentObject__c);
SObjectType childObjectType = gd.get(rus.ChildObject__c);

if(parentObjectType!=null && !gdFields.containsKey(parentObjectType))
gdFields.put(parentObjectType, parentObjectType.getDescribe().fields.getMap());
if(childObjectType!=null && !gdFields.containsKey(childObjectType))
gdFields.put(childObjectType, childObjectType.getDescribe().fields.getMap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>28.0</apiVersion>
</ApexClass>
88 changes: 88 additions & 0 deletions rolluptool/src/pages/RollupSummary_NewPage.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<apex:page standardController="LookupRollupSummary__c" extensions="RollupSummary_NewPage_Controller" showHeader="true" sidebar="true">

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'/>
<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js'/>
<apex:stylesheet value="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>

<apex:sectionHeader title="Lookup Rollup Summary" subtitle="Parent Object"/>
<apex:pageMessages id="msgs"/>

<apex:form id="rusForm">

<apex:pageBlock id="pbs" mode="edit">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!cancel}" value="Cancel" />
</apex:pageBlockButtons>
<!-- Parent Object -->
<apex:pageBlockSection collapsible="false" columns="1" showHeader="true" title="Parent Object" id="parent">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name of lookup definition: " for="childFields"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputField value="{!LookupROllupSummary__c.Name}"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Parent Object:" for="parentObject"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList value="{!LookupRollupSummary__c.ParentObject__c}" id="parentObject" size="1">
<apex:selectOptions value="{!parentObjects}"/>
<apex:actionSupport event="onchange" rerender="parentFields, childObject"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Aggregated Results Field: " for="parentFields"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList value="{!LookupRollupSummary__c.AggregateResultField__c}" id="parentFields" size="1">
<apex:selectOptions value="{!parentFields}"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<!-- child Object -->
<apex:pageBlockSection collapsible="false" columns="1" showHeader="true" title="Child Object" id="child">
<apex:pageBlockSectionItem helpText="{!$ObjectType.LookupRollupSummary__c.Fields.ChildObject__c.inlineHelpText}" >
<apex:outputLabel value="Child Object (Field): " for="parentFields"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList value="{!LookupRollupSummary__c.ChildObject__c}" id="childObject" size="1">
<apex:selectOptions value="{!childObjects}"/>
<apex:actionSupport event="onchange" action="{!setRelationshipField}" reRender="childFields, output" />
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem helpText="{!$ObjectType.LookupRollupSummary__c.Fields.AggregateOperation__c.inlineHelpText}">
<apex:outputLabel value="{!$ObjectType.LookupRollupSummary__c.Fields.AggregateOperation__c.label}" for="childFields"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputField value="{!LookupROllupSummary__c.AggregateOperation__c}">
<apex:actionSupport event="onchange" reRender="child" />
</apex:inputField>
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem helpText="{!$ObjectType.LookupRollupSummary__c.Fields.FieldToAggregate__c.inlineHelpText}" rendered="{!IF(LookupRollupSummary__c.AggregateOperation__c = 'Count',false,true)}">
<apex:outputLabel value="Child field to Aggregate: " for="childFields"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList value="{!LookupRollupSummary__c.FieldToAggregate__c}" id="childFields" size="1">
<apex:selectOptions value="{!childFields}"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection collapsible="false" columns="1" showHeader="true" title="Child Criteria" id="criteria">
<apex:inputField style="width:400px;" value="{!LookupROllupSummary__c.RelationshipCriteria__c}"/>
<apex:inputField style="width:175px; height:100px;" value="{!LookupROllupSummary__c.RelationshipCriteriaFields__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection collapsible="false" columns="1" showHeader="true" title="Calculation" id="mode">
<apex:inputField value="{!LookupROllupSummary__c.CalculationMode__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>
6 changes: 6 additions & 0 deletions rolluptool/src/pages/RollupSummary_NewPage.page-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>28.0</apiVersion>
<label>RollupSummary_NewPage</label>
<description></description>
</ApexPage>

0 comments on commit 7ed63d0

Please sign in to comment.