Wednesday 13 April 2016

lookup rollup summary sample snippets

trigger GK_betaObject_trg on GIRI2__betaObject__c(after insert,after delete,after update) { 
     List<Rollup_Config__c> sfRollup = [Select Id,Parent_Field_Name__c,Parent_Object_Name__c ,Parent_Relation_Name__c,Child_Field_Name__c , 
              Child_Object_Name__c ,Operation_Type__c,Filter1__c,Filter2__c,Filter3__c,Filter4__c,Filter5__c from Rollup_Config__c where Child_Object_Name__c ='GIRI2__betaObject__c' ]; 
     if(sfRollup.size() > 0){ 
         for(Rollup_Config__c conf: sfRollup){ 
             List<Id> pIds = new List<Id>(); 
             List<sobject> dataList = Trigger.IsDelete ?  Trigger.old :Trigger.new; 
             for(sobject rec :  dataList){ 
                pIds.add(String.valueOf(rec.get(conf.Parent_Relation_Name__c))); 
             } 
             if(pIds!=null && pIds.size() > 0){ 
                 System.Debug('pIds : '+pIds); 
                 LookUpConfigBatch batchObj = new LookUpConfigBatch(conf); 
                 batchObj.pIds = pIds; 
                 String batchId = Database.executeBatch(batchObj); 
             } 
         } 
     } 
 }

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


global with sharing class LookUpConfigBatch implements Database.Batchable<sObject>{
    global final String Query;
    global final Rollup_Config__c rollupConf;
    public final List<Id> pIds; // Added in V2
    global LookUpConfigBatch(Rollup_Config__c Conf){
        System.debug(' ============ Apex Batch started ===========');
        System.debug('Conf : '+pIds);
        rollupConf = Conf;
        if(pIds !=null && pIds.size() >0)
            Query = 'Select Id from '+ rollupConf.Parent_Object_Name__c + ' Id =:pIds';
        else
            Query = 'Select Id from '+ rollupConf.Parent_Object_Name__c; // Added in V2
       
       System.debug('batch Query : '+Query );     
   }

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
        
       Set<Id> pObjIds = new Set<Id>();
       for(sobject obj : scope){
           pObjIds.add(String.valueOf(obj.get('Id')));
       }
       String aggriateField=''
       if(rollupConf.Operation_Type__c == 'Count')
           aggriateField = 'Count(Id)' ;
       else
           aggriateField = rollupConf.Operation_Type__c+'('+rollupConf.Child_Field_Name__c+') ';
       
       String strChildQr = 'Select '+ rollupConf.Parent_Relation_Name__c +',' + aggriateField + ' ctr from '+ rollupConf.Child_Object_Name__c + ' where '+ rollupConf.Parent_Relation_Name__c+' =:pObjIds ';
       if(String.isNotEmpty(rollupConf.Filter1__c)){
           strChildQr += ' AND '+rollupConf.Filter1__c.replace('&mp;',' ');
       }
       
       if(String.isNotEmpty(rollupConf.Filter2__c)){
           strChildQr += ' AND '+rollupConf.Filter2__c.replace('&mp;',' ');
       }
       
       if(String.isNotEmpty(rollupConf.Filter3__c)){
           strChildQr += ' AND '+rollupConf.Filter3__c.replace('&mp;',' ');
       }
       
       if(String.isNotEmpty(rollupConf.Filter4__c)){
           strChildQr += ' AND '+rollupConf.Filter4__c.replace('&mp;',' ');
       }
       if(String.isNotEmpty(rollupConf.Filter5__c)){
           strChildQr += ' AND '+rollupConf.Filter5__c.replace('&mp;',' ');
       }
       strChildQr +=' Group By '+ rollupConf.Parent_Relation_Name__c ;
       System.debug('strChildQr : '+strChildQr);
       System.debug('rollupConf : '+rollupConf);
       
       List<sobject> count =Database.query(strChildQr); 
       Map<String,String> agrMap = new Map<String,String>();
       for(sobject obj : count){
           if(String.valueOf(obj.get(rollupConf.Parent_Relation_Name__c)) !=null)
               agrMap.put(String.valueOf(obj.get(rollupConf.Parent_Relation_Name__c)),String.valueOf(obj.get('ctr')));
       }
      
       Set<String> ids = agrMap.keySet();
       
       String strParentQr = 'Select Id,'+ rollupConf.Parent_Field_Name__c +' from '+ rollupConf.Parent_Object_Name__c +' where Id =: ids';
       
       System.debug('strParentQr : '+strParentQr);
       
       List<sobject> objects =Database.query(strParentQr); 
       System.debug('Data  '+objects);
       for(sobject obj : objects){
           Object recid = obj.get('Id');
           Object dat = agrMap.get(String.valueOf(recId));
           if(rollupConf.Operation_Type__c == 'Count')
             obj.put(rollupConf.Parent_Field_Name__c,Integer.valueOf(dat));
           else
               obj.put(rollupConf.Parent_Field_Name__c,Double.valueOf(dat));
       }  
       Update objects;
       System.debug('Data Updated  '+objects);   
    }

   global void finish(Database.BatchableContext BC){
   }

}


+++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/**
 * Copyright (c) 2012, FinancialForce.com, inc
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 *   are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 * - Neither the name of the FinancialForce.com, inc nor the names of its contributors
 *      may be used to endorse or promote products derived from this software without
 *      specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 *  THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 *  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

public with sharing class MetadataDeployController
{
    public String ZipData { get; set; }
    public boolean Ishow { get; set; }
   
    public MetadataService.AsyncResult AsyncResult {get; private set;}
    public String strName='';
    public String strTrg ='';
    public MetadataDeployController(){
   
        if(ApexPages.currentPage().getParameters().containskey('confid')){
            List<Rollup_Config__c> sfRollup = [Select Id,Parent_Field_Name__c,Parent_Object_Name__c ,Parent_Relation_Name__c,Child_Field_Name__c ,
             Child_Object_Name__c ,Operation_Type__c from Rollup_Config__c where Id =:ApexPages.currentPage().getParameters().get('confid') limit 1];
            if(sfRollup.size() > 0 && sfRollup[0].Child_Object_Name__c !=null){
                strName = sfRollup[0].Child_Object_Name__c;
                strTrg = strName.replace('GIRI2__','');
                strTrg = strTrg.replace('__c','')+'_trg';
               
            }
        }   
       
    }
  
  
    public String getPackageXml()
    {
        return '<?xml version="1.0" encoding="UTF-8"?>' +
            '<Package xmlns="http://soap.sforce.com/2006/04/metadata">' +
           
                            '<types>' +
                    '<members>GK_'+ strTrg +'</members>' +
                    '<name>ApexTrigger</name>' +
                '</types>' +
         
             
                '<types>' +
                    '<members>GK_TEST_'+ strTrg +'</members>' +
                    '<name>ApexClass</name>' +
                '</types>' +
           
               '<version>26.0</version>' +
            '</Package>';      
    }
   
    public String getHelloWorldMetadata()
    {
        return '<?xml version="1.0" encoding="UTF-8"?>' +
            '<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">' +
                '<apiVersion>28.0</apiVersion>' +
                '<status>Active</status>' +
            '</ApexTrigger>';    
    }

   
    public String getTestClassMetadata()
    {
        return '<?xml version="1.0" encoding="UTF-8"?>' +
            '<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">' +
                '<apiVersion>28.0</apiVersion>' +
                '<status>Active</status>' +
            '</ApexClass>';    
    }
   
    public String getHelloWorld()  
    {
        return 'trigger GK_'+ strTrg +' on '+ strName +'(after insert,after delete,after update) { \n ' +
        '    List<Rollup_Config__c> sfRollup = [Select Id,Parent_Field_Name__c,Parent_Object_Name__c ,Parent_Relation_Name__c,Child_Field_Name__c , \n ' +
        '             Child_Object_Name__c ,Operation_Type__c,Filter1__c,Filter2__c,Filter3__c,Filter4__c,Filter5__c from Rollup_Config__c where Child_Object_Name__c =\''+ strName +'\' ]; \n ' +
        '    if(sfRollup.size() > 0){ \n ' +
        '        for(Rollup_Config__c conf: sfRollup){ \n ' +
        '            List<Id> pIds = new List<Id>(); \n ' +
        '            List<sobject> dataList = Trigger.IsDelete ?  Trigger.old :Trigger.new; \n ' +
        '            for(sobject rec :  dataList){ \n ' +
        '               pIds.add(String.valueOf(rec.get(conf.Parent_Relation_Name__c))); \n ' +
        '            } \n ' +
        '            if(pIds!=null && pIds.size() > 0){ \n ' +
        '                System.Debug(\'pIds : \'+pIds); \n ' +
        '                LookUpConfigBatch batchObj = new LookUpConfigBatch(conf); \n ' +
        '                batchObj.pIds = pIds; \n ' +
        '                String batchId = Database.executeBatch(batchObj); \n ' +
        '            } \n ' +
        '        } \n ' +
        '    } \n ' +
        '} ';
    }
   
    public String getTestClass()  
    {
        return '@isTest(SeeAllData=true) \n ' +
                'public class GK_TEST_'+ strTrg +' {  \n ' +
                '  static testMethod void GK_Testmethod() {  \n ' +
                '        List<sObject> sourceList = [SELECT Id  \n' +
                '      FROM '+ strName +' LIMIT 1];  \n' +
                '        if(sourceList.size() == 0) {  \n' +
                '            sourceList.add(  \n' +
                '                    new '+ strName +'()  \n' +
                '            );  \n' +
                '        }  \n' +
                '      Database.upsert(sourceList);  \n' +
                '    }  \n' +
                '}' ;

    }
   
    public String getTriggerName(){
       
        return strTrg;   
    }
    public PageReference deployZip()
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, 'Deploying...'));

        // Deploy zip file posted back from the page action function               
        MetadataService.MetadataPort service = createService();
        MetadataService.DeployOptions deployOptions = new MetadataService.DeployOptions();
        deployOptions.allowMissingFiles = false;
        deployOptions.autoUpdatePackage = false;
        deployOptions.checkOnly = false;
        deployOptions.ignoreWarnings = false;
        deployOptions.performRetrieve = false;
        deployOptions.purgeOnDelete = false;
        deployOptions.rollbackOnError = true;
        deployOptions.runAllTests = false;
        deployOptions.runTests = null;
        deployOptions.singlePackage = true;    
        AsyncResult = service.deploy(ZipData, DeployOptions); 
        Ishow=true;            
        return null;
  
    }  
   
    public PageReference checkAsyncRequest()
    {  
        // Check the status of the retrieve request
        MetadataService.MetadataPort service = createService();
        MetadataService.DeployResult deployResult = service.checkDeployStatus(AsyncResult.Id, true);
        if(deployResult.done)
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, 'Deployment completed Successfully'));

            // Deployment errors?
            if(deployResult.details!=null && deployResult.details.componentFailures!=null)
                for(MetadataService.DeployMessage deployMessage : deployResult.details.componentFailures)
                    if(deployMessage.problem!=null)
                        ApexPages.addMessage(
                            new ApexPages.Message(ApexPages.Severity.Error,
                                deployMessage.fileName +
                                    ' (Line: ' + deployMessage.lineNumber + ': Column:' + deployMessage.columnNumber + ') : ' +
                                        deployMessage.problem));
            AsyncResult = null;
        }
        else
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, 'Deploying...'));
        }  
        return null;
    }
   
    private static MetadataService.MetadataPort createService()
    {
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        return service;
          
    }      
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


public with sharing class RollupConfigCtr{

    public String parentObj {get;set;}
    public String parentField {get;set;}
    public String childtObj {get;set;}
    public String childField {get;set;}
    public Boolean isActive{get;set;}
    public String selected {get;set;}
    public String configId {get;set;}
    public String configName {get;set;}
    public Boolean isNew =false;
    //filter//
   // public String filterField {get;set;}
    public String operationType {get;set;}
   
    public String filterField1 {get;set;}
    public String strOperator1{get;set;}
    public String filterField2 {get;set;}
    public String strOperator2 {get;set;}
    public String filterField3 {get;set;}
    public String strOperator3 {get;set;}
    public String filterField4 {get;set;}
    public String strOperator4 {get;set;}
    public String filterField5 {get;set;}
    public String strOperator5 {get;set;}
   
    public String strfilterValue1 {get;set;}
    public String strfilterValue2 {get;set;}
    public String strfilterValue3 {get;set;}
    public String strfilterValue4 {get;set;}
    public String strfilterValue5 {get;set;}
   
    public String strName ='';
    public String strTrg ='';
   
    ///// Pagination ////
    private integer counter=0;  //keeps track of the offset
    private integer list_size=20; //sets the page size or number of rows
    public integer total_size; //used to show user the total size of the list
  
   
    Map<String,String> parentRelMap = new Map<String,String>();
    Map<String,String> dataTypeMap = new Map<String,String>();
    List<SelectOption> ParentFieldOption = new  List<SelectOption>();
    List<SelectOption> ChildRelOption = new  List<SelectOption>();
    List<SelectOption> ChildFieldOption = new  List<SelectOption>();
    List<SelectOption> FilterFieldOption = new  List<SelectOption>();
   
    String tabInFocus = System.currentPageReference().getParameters().get('tab');

    
    public RollupConfigCtr(){
        dataTypeMap = new Map<String,String>();
        dataTypeMap.put('DOUBLE','DOUBLE');
        dataTypeMap.put('CURRENCY','CURRENCY');
        dataTypeMap.put('INTEGER','INTEGER');
        checkConfData();
        total_size = [select count() from Rollup_Config__c]; //set the total size in the constructor
    }
    public List<SelectOption> getParentName(){
        List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();    
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('0','-- Select --'));
        for(Schema.SObjectType f : gd)
        {
            if(f.getDescribe().getChildRelationships() !=null && f.getDescribe().getChildRelationships().size() > 0)
               options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getLabel()));
        }
        return options;
    }

    public List<SelectOption> getChildName(){
        ChildRelOption.clear();
        isActive =false;
        if(String.isNotBlank(parentObj) && parentObj !='0'){
          //  System.debug(' =========================  Test data ==================================== ');
            Schema.SObjectType obj = Schema.getGlobalDescribe().get(parentObj);//Account.SObjectType.getDescribe();
           
            Schema.DescribeSObjectResult R = obj.getDescribe();
            List<Schema.ChildRelationship> C = R.getChildRelationships();
            ChildRelOption.add(new SelectOption('0','-- Select --'));
            for (Schema.ChildRelationship cr: C){
                if(cr.getChildSObject() !=null && cr.getRelationshipName()!=null){
                    //System.debug(' =========================  Test ==================================== ');
                    // System.debug(cr.getRelationshipName());
                     Schema.DescribeFieldResult fieldDesc = cr.getField().getDescribe();
                   // System.debug(fieldDesc.getLabel());
                    //System.debug('Type : ' +fieldDesc.getRelationshipOrder()); //isCustom getType
                   // System.debug('Type : ' + cr.getChildSObject().getDescribe().getRelationshipOrder()); //
                   // System.debug(fieldDesc.getDataType());
                   if(fieldDesc.getRelationshipOrder() ==null){
                        ChildRelOption.add(new SelectOption(cr.getChildSObject().getDescribe().getName(),cr.getChildSObject().getDescribe().getLabel()));
                       // ChildRelOption.add(new SelectOption(cr.getChildSObject().getDescribe().getName(),String.valueOf(cr.getField())));
                        parentRelMap.put(cr.getChildSObject().getDescribe().getName(),String.valueOf(cr.getField()));
                   }
               }
              
            }
            if(ChildRelOption.size() > 1)
                isActive = true;
           
            //System.Debug('parentRelMap : '+parentRelMap.size() +'   ----  '+ChildRelOption.size());   
            return ChildRelOption;
        }
        else{
            return null;
        }
    }
   
    //get child fields for filter criteria //
    public List<SelectOption> getParentFieldData(){
       ParentFieldOption.Clear();
     
        if(String.isNotBlank(parentObj)  && parentObj !='0'){
            Schema.DescribeSObjectResult obj = Schema.getGlobalDescribe().get(parentObj).getDescribe();
            System.debug('Schema:'+obj.fields.getMap());
            Map<String, Schema.SObjectField> fieldMap = obj.fields.getMap();
            ParentFieldOption.add(new SelectOption('0','-- Select --'));
            for(Schema.SObjectField fieldObj :  fieldMap.Values()){
                Schema.DescribeFieldResult fieldDesc = fieldObj.getDescribe();
                if(dataTypeMap.containsKey(String.valueOf(fieldDesc.getType())) && !fieldDesc.isCalculated())
                    ParentFieldOption.add(new SelectOption(fieldDesc.getName(),fieldDesc.getLabel()));
            }
             
        }  
        return ParentFieldOption;
    }
   
    //get child fields for filter criteria //
    public List<SelectOption> getChildFieldData(){
        ChildFieldOption.Clear();
        System.debug('childtObj '+childtObj + ' -- operationType : '+operationType);
        if(String.isNotBlank(childtObj) && childtObj !='0' && operationType !='Count' && operationType !='0'){
       
            Schema.DescribeSObjectResult obj = Schema.getGlobalDescribe().get(childtObj).getDescribe();
            Map<String, Schema.SObjectField> fieldMap = obj.fields.getMap();
            ChildFieldOption.add(new SelectOption('0','-- Select --'));
            for(Schema.SObjectField fieldObj :  fieldMap.Values()){
                Schema.DescribeFieldResult fieldDesc = fieldObj.getDescribe();
                if(dataTypeMap.containsKey(String.valueOf(fieldDesc.getType())))
                    ChildFieldOption.add(new SelectOption(fieldDesc.getName(),fieldDesc.getLabel()));
            }
            System.Debug(' Data field : '+ ChildFieldOption);
        }  
        return ChildFieldOption;
    }
   
    //get child fields for filter criteria //
    Map<String,String>cfieldTypeMap = new Map<String,String>();
    public List<SelectOption> getFilterData(){
        System.Debug('============== Filter ===========');
        FilterFieldOption.Clear();
        System.debug('childtObj '+childtObj + ' -- operationType : '+operationType);
        if(String.isNotBlank(childtObj)){
            Schema.DescribeSObjectResult obj = Schema.getGlobalDescribe().get(childtObj).getDescribe();
            Map<String, Schema.SObjectField> fieldMap = obj.fields.getMap();
            FilterFieldOption.add(new SelectOption('','-- None --'));
            for(Schema.SObjectField fieldObj :  fieldMap.Values()){
                Schema.DescribeFieldResult fieldDesc = fieldObj.getDescribe();   
                FilterFieldOption.add(new SelectOption(fieldDesc.getName(),fieldDesc.getLabel()+' -- '+String.valueOf(fieldDesc.getType())));
                cfieldTypeMap.put(fieldDesc.getName(),String.valueOf(fieldDesc.getType()));
            }
        }
        System.Debug(' Filter field : '+ FilterFieldOption);  
        return FilterFieldOption;
    }
    //get operator type
    //get child fields for filter criteria //
    public List<SelectOption> getOperator(){
        List<SelectOption> operations = new  List<SelectOption>();
       if(isActive){
            //System.debug('childtObj '+childtObj );
            operations.add(new SelectOption('','-- None -- '));
            operations.add(new SelectOption('=','Eqauls To'));
            operations.add(new SelectOption('>','Greater Than'));
            operations.add(new SelectOption('<','Less Than'));
            operations.add(new SelectOption('IN','IN'));
            operations.add(new SelectOption('NOT IN','NOT IN'));
      }
        return operations;
    }
    //get child fields for filter criteria //
    public List<SelectOption> getOperationData(){
        List<SelectOption> operations = new  List<SelectOption>();
       if(isActive){
            //System.debug('childtObj '+childtObj );
            operations.add(new SelectOption('0','-- Select -- '));
            operations.add(new SelectOption('Count','Count'));
            operations.add(new SelectOption('Sum','Sum '));
            operations.add(new SelectOption('Min','Min'));
            operations.add(new SelectOption('Max','Max'));
            operations.add(new SelectOption('Avg','Avg'));
      }
        return operations;
    }
   
  
   
    public PageReference SaveRunConfig(){
       
        Rollup_Config__c record = SaveConfig();
        LookUpConfigBatch batchObj = new LookUpConfigBatch(record);
        String batchId = Database.executeBatch(batchObj);
        PageReference newocp = new PageReference('/apexpages/setup/listAsyncApexJobs.apexp');
        newocp.setRedirect(true);
        return newocp;
    }
   
    public PageReference Save(){
         SaveConfig();
         selected ='List';
         return null;
     }
   
    //save Rollup_Config__c records.
    public Rollup_Config__c SaveConfig(){
   
        try{
            if(parentObj =='0' || parentObj ==null){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select Parent Object.'));
                return null;
            }
            if(parentField =='0' || parentField ==null){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select parent object field.'));
                return null;
            }
            if(childtObj =='0' || childtObj ==null){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select child Object.'));
                return null;
            }
            if(operationType =='0' || operationType ==null){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select operation type.'));
                return null;
            }
            if(operationType !='Count' && childField =='0'){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select child object field.'));
                return null;
            }
           
           
            Rollup_Config__c sfrec = new Rollup_Config__c();
            String strParent = parentRelMap.get(childtObj);
         
            sfrec = new Rollup_Config__c(Name = configName,Parent_Field_Name__c =parentField ,Parent_Object_Name__c =parentObj ,
                Parent_Relation_Name__c =strParent , Child_Field_Name__c = childField , Child_Object_Name__c = childtObj , Operation_Type__c = operationType);
            // Filter check //
            if(String.isNotEmpty(filterField1) && String.isNotEmpty(strOperator1) && String.isNotEmpty(strfilterValue1)){
                strfilterValue1 = getfilterValue(filterField1,strOperator1,strfilterValue1);
                sfrec.Filter1__c = filterField1 + '&mp;'+strOperator1+'&mp;'+ strfilterValue1;
            }
            if(String.isNotEmpty(filterField2) && String.isNotEmpty(strOperator2) && String.isNotEmpty(strfilterValue2)){
                strfilterValue2 = getfilterValue(filterField2,strOperator2,strfilterValue2);
                sfrec.Filter2__c = filterField2 + '&mp;'+strOperator2+'&mp;'+ strfilterValue2;
            }
            if(String.isNotEmpty(filterField3) && String.isNotEmpty(strOperator3) && String.isNotEmpty(strfilterValue3)){
                strfilterValue3 = getfilterValue(filterField3,strOperator3,strfilterValue3);
                sfrec.Filter3__c = filterField3 + '&mp;'+strOperator3+'&mp;'+ strfilterValue3;
            }
            if(String.isNotEmpty(filterField4) && String.isNotEmpty(strOperator4) && String.isNotEmpty(strfilterValue4)){
                strfilterValue4 = getfilterValue(filterField4,strOperator4,strfilterValue4);
                sfrec.Filter4__c = filterField4 + '&mp;'+strOperator4+'&mp;'+ strfilterValue4;
            }
            if(String.isNotEmpty(filterField5) && String.isNotEmpty(strOperator5) && String.isNotEmpty(strfilterValue5)){
                strfilterValue5 = getfilterValue(filterField5,strOperator5,strfilterValue5);
                sfrec.Filter5__c = filterField5 + '&mp;'+strOperator5+'&mp;'+ strfilterValue5;
            }
               
            if(ApexPages.currentPage().getParameters().containsKey('recid')){
                 sfrec.Id = configid;      
                 update sfrec;      
            }else{ insert sfrec; }
         
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Record Saved Successfully')); 
            return sfrec;
        }
        catch(Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error in config. Please contact to administrator with the error : '+ ex.getMessage()));
            return null;
        }                  
    }
   
    public string getfilterValue(String field,String Operator,String value){
        String data= '';
        String dataType = cfieldTypeMap.get(field);
       // dataTypeMap.containsKey(cfieldTypeMap.get(filterField5)) || cfieldTypeMap.get(filterField5)=='BOOLEAN' ? strfilterValue5 : +'\''+strfilterValue5 +'\'';
        if(dataTypeMap.containsKey(dataType)){
            if(Operator =='IN' || Operator =='NOT IN'){
              data = '('+value+')'; 
            }
            else
                data = value ;
      }
      else if(dataType =='BOOLEAN'){
           data = value ;
      }
      else{
          if(Operator =='IN' || Operator =='NOT IN'){
              List<String> datList = value.split(',');
              System.debug('datList : '+datList);
              for(String dat :datList){
                  data += String.isEmpty(data) ? '\''+dat+'\'' : ',\''+dat+'\'';
              } 
              data =  '('+data+')'; 
            }
            else
                data =  '\''+data+'\''; 
      }
       return data;
    }
   
  
     // Get List of the Config //
     public Map<Id,Rollup_Config__c> rollupMap = new Map<Id,Rollup_Config__c>();
     public List<Rollup_Config__c> getConfigRecs(){
         rollupMap = new Map<Id,Rollup_Config__c>([Select Id,Name,Parent_Field_Name__c,Parent_Object_Name__c ,Parent_Relation_Name__c,Child_Field_Name__c ,
             Child_Object_Name__c ,Operation_Type__c,Filter1__c,Filter2__c,Filter3__c,Filter4__c,Filter5__c from Rollup_Config__c limit :list_size Offset :counter]);
        // System.debug('datList : '+rollupMap.values());
         if(rollupMap !=null && rollupMap.size() >0)
             return rollupMap.values();
         else
             return null;          
     }

     public PageReference Cancel(){
         PageReference newocp = new PageReference('/apex/LookUp');
         newocp.setRedirect(true);
         return newocp;
     }
    
     public PageReference doRun(){
       //  System.debug('configId : '+configId); 
         if(!String.isEmpty(configId) && rollupMap.containsKey(configId)){
             Rollup_Config__c sfRollup = rollupMap.get(configId) ;
             LookUpConfigBatch batchObj = new LookUpConfigBatch(sfRollup);
             String batchId = Database.executeBatch(batchObj);
             PageReference newocp = new PageReference('/apexpages/setup/listAsyncApexJobs.apexp');
             newocp.setRedirect(true);
             return newocp;
         }
         else
             return null;
     }
 
     public PageReference deleteConfig(){
        // System.debug('configId  '+configId);
         if(!String.isEmpty(configId)){
             try{
                 Delete new Rollup_Config__c(Id=configId);
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Record Deleted Successfully'));
             }catch(DMLException ex){
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error in config. Please contact to administrator with the error : '+ ex.getMessage()));
             }
           
         }
         return null;
     }
    
     public PageReference scheduleConfig(){
        // System.debug('configId  '+configId);
         if(!String.isEmpty(configId) && rollupMap.containsKey(configId)){
             PageReference pg = new PageReference('/apex/Deploy?core.apexpages.request.devconsole=1&confid='+configId);
             pg.setRedirect(true);
             return pg ;
         }
         else
             return null;
     }
    
     public PageReference Edit(){
    
         System.debug('Edit configId  '+configId +' -- map --'+rollupMap.containsKey(configId));
         if(!String.isEmpty(configId) && rollupMap.containsKey(configId)){
             PageReference pg = new PageReference('/apex/LookUp');
             pg.getParameters().put('recid', configId);
             pg.setRedirect(true);
             return pg ;
         }
         else
             return null;
     }

     public void checkConfData(){
         getConfigRecs();
        // System.debug('isNew : '+Apexpages.currentPage().getParameters().containsKey('recid'));
         if(Apexpages.currentPage().getParameters().containsKey('recid')
             && rollupMap.containsKey(Apexpages.currentPage().getParameters().get('recid'))){
             configId = Apexpages.currentPage().getParameters().get('recid');
             Rollup_Config__c sfRollup = rollupMap.get(configId) ;
            // System.debug('sfRollup '+sfRollup);
             configName = sfRollup.Name;
             parentObj = sfRollup.Parent_Object_Name__c;
             parentField = sfRollup.Parent_Field_Name__c;
             childtObj = sfRollup.Child_Object_Name__c;
             childField = sfRollup.Child_Field_Name__c;
             operationType = sfRollup.Operation_Type__c;
            
              //filter //
             if(String.isNotEmpty(sfRollup.Filter1__c) && sfRollup.Filter1__c.Split('&mp;').size() ==3){
                 List<String> filters = new List<String>();
                 filters = sfRollup.Filter1__c.Split('&mp;');
                 System.debug('filters : '+filters[0] +' - '+filters[1]+' - '+filters[2]);
                 filterField1 = filters[0];
                 strOperator1 = filters[1];
                 strfilterValue1 = filters[2].replace('\'','').replace('(','').replace(')','');
             }
             if(String.isNotEmpty(sfRollup.Filter2__c) && sfRollup.Filter2__c.Split('&mp;').size() ==3){
                 List<String> filters = new List<String>();
                 filters = sfRollup.Filter2__c.Split('&mp;');
                 filterField2 = filters[0];
                 strOperator2 = filters[1];
                 strfilterValue2 = filters[2].replace('\'','').replace('(','').replace(')','');
             }
             if(String.isNotEmpty(sfRollup.Filter3__c) && sfRollup.Filter3__c.Split('&mp;').size() ==3){
                 List<String> filters = new List<String>();
                 filters = sfRollup.Filter3__c.Split('&mp;');
                 filterField3 = filters[0];
                 strOperator3 = filters[1];
                 strfilterValue3 = filters[2].replace('\'','').replace('(','').replace(')','');
             }
             if(String.isNotEmpty(sfRollup.Filter4__c) && sfRollup.Filter4__c.Split('&mp;').size() ==3){
                 List<String> filters = new List<String>();
                 filters = sfRollup.Filter4__c.Split('&mp;');
                 filterField4 = filters[0];
                 strOperator4 = filters[1];
                 strfilterValue4 = filters[2].replace('\'','').replace('(','').replace(')','');
             }
             if(String.isNotEmpty(sfRollup.Filter5__c) && sfRollup.Filter5__c.Split('&mp;').size() ==3){
                 List<String> filters = new List<String>();
                 filters = sfRollup.Filter5__c.Split('&mp;');
                 filterField5 = filters[0];
                 strOperator5 = filters[1];
                 strfilterValue5 = filters[2].replace('\'','').replace('(','').replace(')','');
             }
              
             String urlVal = Apexpages.currentPage().getUrl();
             selected = 'Create';
        
        }
         else{
             selected = 'List';
             configId ='';
             configName = '';
             parentObj = '';
             parentField = '';
             childtObj = '';
             childField = '';
             operationType = '';
             String urlVal = '';
         }
     }
     public PageReference Add(){
    // System.debug('asd');
        selected = 'Create';
         configId ='';
         configName = '';
         parentObj = '';
         parentField = '';
         childtObj = '';
         childField = '';
         operationType = '';
         String urlVal = '';
        return null;
     }
     ////////// Pagination //////////////////
      public PageReference Beginning() { //user clicked beginning
          counter = 0;
          return null;
       }
    
       public PageReference Previous() { //user clicked previous button
          counter -= list_size;
          return null;
       }
    
       public PageReference Next() { //user clicked next button
          System.debug('counter : '+counter+' - '+list_size);
          counter += list_size;
          return null;
       }
    
       public PageReference End() { //user clicked end
          counter = total_size - math.mod(total_size, list_size);
         // System.debug('counter : '+counter);
          return null;
       }
    
       public Boolean getDisablePrevious() {
          //this will disable the previous and beginning buttons
          if (counter>0) return false; else return true;
       }
    
       public Boolean getDisableNext() { //this will disable the next and end buttons
          if (counter + list_size <= total_size) return false; else return true;
       }
    
       public Integer getTotal_size() {
          return total_size;
       }
    
       public Integer getPageNumber() {
          return counter/list_size + 1;
       }
    
       public Integer getTotalPages() {
          if (math.mod(total_size, list_size) > 0) {
             return total_size/list_size + 1;
          } else {
             return (total_size/list_size);
          }
       }
      
       public static void RunJob(Rollup_Config__c conf){
             LookUpConfigBatch batchObj = new LookUpConfigBatch(conf);
             String batchId = Database.executeBatch(batchObj);
       }

}


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


<apex:page controller="RollupConfigCtr" sidebar="false" >
<apex:stylesheet value="{!URLFOR($Resource.FontAwesome, '/css-n-fonts/font-awesome.css')}"/>
    <script type="text/javascript">

        /*
        *    function to handle checkbox selection
        */
        function doAction(action,itemId){
           if(action =='Run'){
               runConfig(itemId);
           }
           else if(action =='Edit'){
               editConfig(itemId);
           }
           else if(action =='Delete'){
               if(confirm("Do you want to delete this config !")){
                   delConfig(itemId);
               }
               //else{ return false; }
           } 
           else if(action == 'Schedule'){
               schConfig(itemId);
           } 
        }
       
        function loading(val) {
        if (val) {
          document.getElementById('contentLoading').style.display = 'block';
          document.getElementById('contentLoaded').style.display = 'none';
        }
        else {
          document.getElementById('contentLoading').style.display = 'none';
          document.getElementById('contentLoaded').style.display = 'block';
        }
      }
      /// show/hide filter box
      function showFilter(input, textid) {
            if(input.checked) {
                document.getElementById(textid).style.display= "block";
            }
            else {
                document.getElementById(textid).style.display= "none";
            }
       }
      
       /// show/hide filter box
      function hideFilter(input, textid) {
            if(input.checked) {
                document.getElementById(textid).style.display= "none";
            }
            else {
                document.getElementById(textid).style.display= "block";
            }
       }
       </script>
   
   <style type="text/css">
        .overlay {
            display: none;
            height: 100%;
            left: 0;
            position: fixed;
            top: 0;
            opacity: 0.3;
            -moz-opacity: 0.3;
            width: 100%;
            -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
            filter: alpha(opacity=30);
            background: #77b55a;
            -khtml-opacity: 0.3;
            z-index: 1000;
        }
        .loader {
            background: url('/img/loading32.gif') scroll no-repeat 0 0;
            width: 32px;
            height: 32px;
            position: absolute;
            left: 50%;
            top:50%;
        }
       
        .selectWidth{
            width:300px;
        }
       
        .AddButton
        {
            width:250px;
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc!important;
            padding:12px 44px;
        }
        .Button
        {
            width:70px;
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc!important;
        }
       
        
        .ScheduleButton
        {
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc !important
        }
       
        .Save2Button
        {
            width:100px;
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc !important
        }     
      
        .headerRow
        {
            background-image: none ;
            color: #CC0000 !important;
            font-size:110% !important;
        }      
        .pbHeader
        {
            background-color: #337AB7 !important;
            color: white !important;
        }
       
      
    </style>
   
    <apex:form >
      <apex:tabPanel switchType="client" value="{!selected}"  id="theTabPanel" >
        <apex:tab label="Configs List" name="List" id="List">
            <!-- Run Configuration -->
            <apex:actionFunction name="runConfig" action="{!doRun}" rerender="confList" >
                <apex:param name="contextItem" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
             <!-- Schedule Configuration -->
            <apex:actionFunction name="schConfig" action="{!scheduleConfig}" rerender="confList" >
                <apex:param name="contextItem" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
            <!-- Edit Configuration -->
            <apex:actionFunction name="editConfig" action="{!Edit}"  rerender="theTabPanel" >
                <apex:param name="contextItem1" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
            <!-- Delete Configuration -->
            <apex:actionFunction name="delConfig" action="{!deleteConfig}" rerender="confList" >
                <apex:param name="contextItem" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
            <apex:outputPanel styleClass="headerRow" >
             <apex:pageBlock title="Rollup Congif List" tabStyle="Account">
                
          
                <!-- Config data -->
            <apex:pageBlockTable id="confList"   value="{!ConfigRecs}" var="rec">
                <apex:column style="min-width:100px;p" >
                    <apex:facet name="header" >Action</apex:facet>
                   <div style="float:left;">
                      <i class="icon-youtube-play">Run</i>
                      <img src="{!$Resource.run}" title="Run" onclick="doAction('Run','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>
                      <img src="{!$Resource.Edit}" title="Edit" onclick="doAction('Edit','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>
                      <img src="{!$Resource.Schedule}" title="Schedule" onclick="doAction('Schedule','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>                                          
                      <img src="{!$Resource.Delete}" title="Delete" onclick="doAction('Delete','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>
                   </div>
                    <!--<apex:commandButton styleClass="Button" value="Run" onclick="doAction('Run','{!rec.Id}'); return false;" /> -->
                   <!-- <apex:commandButton styleClass="Button" value="Edit" onclick="doAction('Edit','{!rec.Id}'); return false;" /> -->
                   <!-- <apex:commandButton styleClass="ScheduleButton" value="Schedule" onclick="doAction('Schedule','{!rec.Id}'); return false;" /> -->
                   <!-- <apex:commandButton styleClass="Button" value="Delete" onclick="doAction('Delete','{!rec.Id}'); return false;" /> -->                  
                </apex:column>
               
                <apex:column value="{!rec.Name}"/>
                <apex:column value="{!rec.Parent_Object_Name__c}"/>
                <apex:column value="{!rec.Parent_Field_Name__c}"/>
                <apex:column value="{!rec.Child_Object_Name__c}"/>
                <apex:column value="{!rec.Child_Field_Name__c}"/>
                <apex:column value="{!rec.Operation_Type__c}"/>
                <apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
            </apex:pageBlockTable>
            <apex:pageblockbuttons styleClass="headerRow" location="top">
                <apex:commandButton styleClass="AddButton" action="{!Add}" value="Add New Config"/>
            </apex:pageblockbuttons>
            <apex:pageBlockButtons location="bottom">
                <apex:outputPanel >
                    <apex:commandButton action="{!Beginning}" title="Beginning" value="<<" disabled="{!disablePrevious}" reRender="confList,myButtons"/>
                    <apex:commandButton action="{!Previous}" title="Previous" value="<" disabled="{!disablePrevious}" reRender="confList,myButtons"/>       
                    <apex:commandButton action="{!Next}" title="Next" value=">" reRender="confList,myButtons"/>
                    <apex:commandButton action="{!End}" title="End" value=">>" disabled="{!disableNext}" reRender="confList,myButtons"/>       
                 </apex:outputPanel>
           </apex:pageBlockButtons>
            </apex:pageBlock>
                 </apex:outputPanel>
        </apex:tab>
        <apex:tab label="Create New Config" name="Create" id="Create">
           <apex:pageMessages id="showmsg"></apex:pageMessages>
            <apex:pageBlock tabStyle="Account" title="New Rollup Configuration" >
               
              <apex:pageblockSection columns="1"  >
                  <apex:pageBlockSectionItem >
                      <apex:outputLabel > Configuration Name: </apex:outputLabel>
                      <apex:inputText value="{!configName}" styleClass="selectWidth" />
                  </apex:pageBlockSectionItem>
                  <apex:pageBlockSectionItem >
                      <apex:outputLabel > Master Object : </apex:outputLabel>
                      <apex:SelectList value="{!parentObj}" size="1" styleClass="selectWidth" >
                          <apex:selectOptions value="{!ParentName}"></apex:selectOptions>
                          <apex:actionSupport event="onchange" reRender="childRel,pField" status="loading" />
                     </apex:SelectList>
                  </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                      <apex:outputLabel > Master Object Field To Poppulate: </apex:outputLabel>
                     
                      <apex:SelectList value="{!parentField}" size="1" id="pField" styleClass="selectWidth" >
                          <apex:selectOptions value="{!ParentFieldData}"></apex:selectOptions>
                     </apex:SelectList>
                    
                 </apex:pageBlockSectionItem>
                
                 <apex:pageBlockSectionItem >
                      <apex:outputLabel > Summarized Object: </apex:outputLabel>
                     
                      <apex:SelectList value="{!childtObj}" size="1" id="childRel" styleClass="selectWidth"  >
                          <apex:selectOptions value="{!ChildName}"></apex:selectOptions>
                          <apex:actionSupport event="onchange"  status="loading" reRender="Operation,catType,cFilter" />
                     </apex:SelectList>
                 </apex:pageBlockSectionItem>
                
                 <apex:pageBlockSectionItem >
                
                     <apex:outputLabel > Select Roll-Up Type : </apex:outputLabel>
                     <apex:actionRegion >
                          <apex:SelectList value="{!operationType}" id="catType"  size="1" styleClass="selectWidth"  >
                              <apex:selectOptions value="{!OperationData}"></apex:selectOptions>
                              <apex:actionSupport event="onchange" status="loading" reRender="Operation,cField" />
                         </apex:SelectList>
                     </apex:actionRegion>
                 </apex:pageBlockSectionItem>
                <!--  <apex:commandButton action="{!getChild}" value="Data"/>-->
              </apex:pageblockSection>
             
                <apex:outputPanel id="Operation" styleClass="headerRow" >
                   <apex:pageBlockSection title="Summary Operation" rendered="{!if(operationType !='0' && operationType !='Count' && operationType !=null,true,false)}">
                       <apex:pageBlockSectionItem >
                         <apex:outputLabel > Field to Aggregate : </apex:outputLabel>
                         
                          <apex:SelectList required="true" value="{!childField}" size="1" id="cField"  >
                              <apex:selectOptions value="{!ChildFieldData}"></apex:selectOptions>
                         </apex:SelectList>
                     </apex:pageBlockSectionItem>  
                  </apex:pageBlockSection>     
                </apex:outputPanel>           
          </apex:pageBlock>
         
                  <div align="center" draggable="false" >
                       <apex:commandButton styleClass="Button" action="{!Save}" value="Save"/>
                         <apex:commandButton styleClass="Save2Button" action="{!SaveRunConfig}" value="Save&Run"/>
                       <apex:commandButton styleClass="Button" value="Cancel" action="{!Cancel}" />
                  </div>
                 
        </apex:tab>
    </apex:tabPanel>
    <apex:actionStatus id="loading" onstart="loading(true)" onstop="loading(false)" /> 
    <div id="contentLoading" class="overlay" style="display:none;">
        <div class="loader"> </div>
    </div>
    </apex:form>
</apex:page>
https://ssl.gstatic.com/ui/v1/icons/mail/profile_mask2.png
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<apex:page controller="RollupConfigCtr" sidebar="false" >
<apex:stylesheet value="{!URLFOR($Resource.FontAwesome, '/css-n-fonts/font-awesome.css')}"/>
    <script type="text/javascript">
 
        /*
        *    function to handle checkbox selection
        */
        function doAction(action,itemId){
           if(action =='Run'){
               runConfig(itemId);
           }
           else if(action =='Edit'){
               editConfig(itemId);
           }
           else if(action =='Delete'){
               if(confirm("Do you want to delete this config !")){
                   delConfig(itemId);
               }
               //else{ return false; }
           }  
           else if(action == 'Schedule'){
               schConfig(itemId);
           }  
        }
        
        function loading(val) {
        if (val) {
          document.getElementById('contentLoading').style.display = 'block';
          document.getElementById('contentLoaded').style.display = 'none';
        }
        else {
          document.getElementById('contentLoading').style.display = 'none';
          document.getElementById('contentLoaded').style.display = 'block';
        }
      }
      /// show/hide filter box
      function showFilter(input, textid) {
            if(input.checked) {
                document.getElementById(textid).style.display= "block";
            }
            else {
                document.getElementById(textid).style.display= "none";
            }
       }
       
       /// show/hide filter box
      function hideFilter(input, textid) {
            if(input.checked) {
                document.getElementById(textid).style.display= "none";
            }
            else {
                document.getElementById(textid).style.display= "block";
            }
       }
       </script>
    
   <style type="text/css">
        .overlay {
            display: none;
            height: 100%;
            left: 0;
            position: fixed;
            top: 0;
            opacity: 0.3;
            -moz-opacity: 0.3;
            width: 100%;
            -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
            filter: alpha(opacity=30);
            background: #77b55a;
            -khtml-opacity: 0.3;
            z-index: 1000;
        }
        .loader {
            background: url('/img/loading32.gif') scroll no-repeat 0 0;
            width: 32px;
            height: 32px;
            position: absolute;
            left: 50%;
            top:50%;
        }
        
        .selectWidth{
            width:300px;
        }
        
        .AddButton
        {
            width:250px;
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc!important;
            padding:12px 44px;
        }
        .Button
        {
            width:70px;
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc!important;
        }
        
        
        .ScheduleButton
        {
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc !important
        }
        
        .Save2Button
        {
            width:100px;
            height:30px;
            color:#7777777 !important;
            font-size:110% !important;
            background:#dcdcdc !important
        }      
       
        .headerRow 
        {
            background-image: none ;
            color: #CC0000 !important; 
            font-size:110% !important; 
        }       
        .pbHeader
        {
            background-color: #337AB7 !important;
            color: white !important;
        }
        
       
    </style>
    
    <apex:form >
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
      <apex:tabPanel switchType="client" value="{!selected}"  id="theTabPanel" >
        <apex:tab label="Configs List" name="List" id="List">
            <!-- Run Configuration -->
            <apex:actionFunction name="runConfig" action="{!doRun}" rerender="confList" >
                <apex:param name="contextItem" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
             <!-- Schedule Configuration -->
            <apex:actionFunction name="schConfig" action="{!scheduleConfig}" rerender="confList" >
                <apex:param name="contextItem" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
            <!-- Edit Configuration -->
            <apex:actionFunction name="editConfig" action="{!Edit}"  rerender="theTabPanel" >
                <apex:param name="contextItem1" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
            <!-- Delete Configuration -->
            <apex:actionFunction name="delConfig" action="{!deleteConfig}" rerender="confList" >
                <apex:param name="contextItem" value="" assignTo="{!configId}"/>
            </apex:actionFunction>
            <apex:outputPanel styleClass="headerRow" >
             <apex:pageBlock title="Rollup Congif List" tabStyle="Account">
                
           
                <!-- Config data -->
            <apex:pageBlockTable id="confList"   value="{!ConfigRecs}" var="rec">
                <apex:column style="min-width:100px;p" >
                    <apex:facet name="header" >Action</apex:facet>
                   <div style="float:left;">
                      <i class="icon-youtube-play">Run</i>
                      <img src="{!$Resource.run}" title="Run" onclick="doAction('Run','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>
                      <img src="{!$Resource.Edit}" title="Edit" onclick="doAction('Edit','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/> 
                      <img src="{!$Resource.Schedule}" title="Schedule" onclick="doAction('Schedule','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>                                           
                      <img src="{!$Resource.Delete}" title="Delete" onclick="doAction('Delete','{!rec.Id}'); return false;" style="cursor:pointer;Padding-right:5px;"/>
                   </div>
                    <!--<apex:commandButton styleClass="Button" value="Run" onclick="doAction('Run','{!rec.Id}'); return false;" /> -->
                   <!-- <apex:commandButton styleClass="Button" value="Edit" onclick="doAction('Edit','{!rec.Id}'); return false;" /> -->
                   <!-- <apex:commandButton styleClass="ScheduleButton" value="Schedule" onclick="doAction('Schedule','{!rec.Id}'); return false;" /> -->
                   <!-- <apex:commandButton styleClass="Button" value="Delete" onclick="doAction('Delete','{!rec.Id}'); return false;" /> -->                   
                </apex:column>
                
                <apex:column value="{!rec.Name}"/>
                <apex:column value="{!rec.Parent_Object_Name__c}"/>
                <apex:column value="{!rec.Parent_Field_Name__c}"/>
                <apex:column value="{!rec.Child_Object_Name__c}"/>
                <apex:column value="{!rec.Child_Field_Name__c}"/>
                <apex:column value="{!rec.Operation_Type__c}"/>
                <apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
            </apex:pageBlockTable>
            <apex:pageblockbuttons styleClass="headerRow" location="top">
                <apex:commandButton styleClass="AddButton" action="{!Add}" value="Add New Config"/>
            </apex:pageblockbuttons>
            <apex:pageBlockButtons location="bottom">
                <apex:outputPanel >
                    <apex:commandButton action="{!Beginning}" title="Beginning" value="<<" disabled="{!disablePrevious}" reRender="confList,myButtons"/>
                    <apex:commandButton action="{!Previous}" title="Previous" value="<" disabled="{!disablePrevious}" reRender="confList,myButtons"/>        
                    <apex:commandButton action="{!Next}" title="Next" value=">" reRender="confList,myButtons"/>
                    <apex:commandButton action="{!End}" title="End" value=">>" disabled="{!disableNext}" reRender="confList,myButtons"/>        
                 </apex:outputPanel>
           </apex:pageBlockButtons>
            </apex:pageBlock>
                 </apex:outputPanel>
        </apex:tab>
        <apex:tab label="Create New Config" name="Create" id="Create">
           <apex:pageMessages id="showmsg"></apex:pageMessages>
            <apex:pageBlock tabStyle="Account" title="New Rollup Configuration" >
                
              <apex:pageblockSection columns="1"  >
                  <apex:pageBlockSectionItem >
                      <apex:outputLabel > Configuration Name: </apex:outputLabel>
                      <apex:inputText value="{!configName}" styleClass="selectWidth" />
                  </apex:pageBlockSectionItem>
                  <apex:pageBlockSectionItem >
                      <apex:outputLabel > Master Object : </apex:outputLabel>
                      <apex:SelectList value="{!parentObj}" size="1" styleClass="selectWidth" >
                          <apex:selectOptions value="{!ParentName}"></apex:selectOptions>
                          <apex:actionSupport event="onchange" reRender="childRel,pField" status="loading" />
                     </apex:SelectList>
                  </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >
                      <apex:outputLabel > Master Object Field To Poppulate: </apex:outputLabel>
                      
                      <apex:SelectList value="{!parentField}" size="1" id="pField" styleClass="selectWidth" >
                          <apex:selectOptions value="{!ParentFieldData}"></apex:selectOptions>
                     </apex:SelectList>
                     
                 </apex:pageBlockSectionItem>
                 
                 <apex:pageBlockSectionItem >
                      <apex:outputLabel > Summarized Object: </apex:outputLabel>
                      
                      <apex:SelectList value="{!childtObj}" size="1" id="childRel" styleClass="selectWidth"  >
                          <apex:selectOptions value="{!ChildName}"></apex:selectOptions>
                          <apex:actionSupport event="onchange"  status="loading" reRender="Operation,catType,cFilter" />
                     </apex:SelectList>
                 </apex:pageBlockSectionItem>
                 
                 <apex:pageBlockSectionItem >
                 
                     <apex:outputLabel > Select Roll-Up Type : </apex:outputLabel>
                     <apex:actionRegion >
                          <apex:SelectList value="{!operationType}" id="catType"  size="1" styleClass="selectWidth"  >
                              <apex:selectOptions value="{!OperationData}"></apex:selectOptions>
                              <apex:actionSupport event="onchange" status="loading" reRender="Operation,cField" />
                         </apex:SelectList>
                     </apex:actionRegion>
                 </apex:pageBlockSectionItem>
                <!--  <apex:commandButton action="{!getChild}" value="Data"/>-->
              </apex:pageblockSection>
              
                <apex:outputPanel id="Operation" styleClass="headerRow" >
                   <apex:pageBlockSection title="Summary Operation" rendered="{!if(operationType !='0' && operationType !='Count' && operationType !=null,true,false)}">
                       <apex:pageBlockSectionItem >
                         <apex:outputLabel > Field to Aggregate : </apex:outputLabel>
                         
                          <apex:SelectList required="true" value="{!childField}" size="1" id="cField"  >
                              <apex:selectOptions value="{!ChildFieldData}"></apex:selectOptions>
                         </apex:SelectList>
                     </apex:pageBlockSectionItem>   
                  </apex:pageBlockSection>      
                </apex:outputPanel>            
          </apex:pageBlock>
          
                  <div align="center" draggable="false" >
                       <apex:commandButton styleClass="Button" action="{!Save}" value="Save"/>
                         <apex:commandButton styleClass="Save2Button" action="{!SaveRunConfig}" value="Save&Run"/>
                       <apex:commandButton styleClass="Button" value="Cancel" action="{!Cancel}" />
                  </div>
                  
        </apex:tab>
    </apex:tabPanel>
    <apex:actionStatus id="loading" onstart="loading(true)" onstop="loading(false)" />  
    <div id="contentLoading" class="overlay" style="display:none;">
        <div class="loader"> </div>
    </div>
    </apex:form>
</apex:page>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


<apex:form id="form">
        <apex:sectionHeader title="Schedule Lookup Summary Job"/>
        <apex:pageMessages />
        <apex:actionPoller action="{!checkAsyncRequest}" interval="5" rerender="form" rendered="{!NOT(ISNULL(AsyncResult))}"/>
        <apex:actionFunction name="deployZip" action="{!deployZip}" rendered="{!ISNULL(AsyncResult)}" rerender="form">
            <apex:param name="data" assignTo="{!ZipData}" value=""/>
        </apex:actionFunction>
        <c:Zip name="generateZip" oncomplete="deployZip(data);" rendered="{!ISNULL(AsyncResult)}">
            <c:ZipEntry path="package.xml" data="{!PackageXml}"/>
            
            <c:ZipEntry path="classes/GK_TEST_{!TriggerName}.cls-meta.xml" data="{!TestClassMetadata}"/>
             <c:ZipEntry path="classes/GK_TEST_{!TriggerName}.cls" data="{!TestClass}"/> 
             
            <c:ZipEntry path="triggers/GK_{!TriggerName}.trigger-meta.xml" data="{!HelloWorldMetadata}"/>
             <c:ZipEntry path="triggers/GK_{!TriggerName}.trigger" data="{!HelloWorld}"/> 
             
             
              
        </c:Zip>
        <apex:outputPanel rendered="{!ISNULL(AsyncResult)}">
        
           <apex:pageBlock rendered="{!! Ishow=true}" >
           
           
          
           
           
           
           
           <apex:pageBlockSection columns="1">
           <apex:pageBlockSectionItem >
        <apex:commandButton styleClass="Button" value="View Config Data" action="{!ViewData}" /> 
         
         </apex:pageBlockSectionItem>
             
           </apex:pageBlockSection>
               <apex:pageBlockSection >
           
                Click "Deploy"  {!TriggerName} Button to deploy  
              
               </apex:pageBlockSection>
               
            <input type="button" onclick="generateZip();" value="Deploy"/>
            
           </apex:pageBlock>
           <apex:pageBlock rendered="{!! Ishow=false}">
           
         
            
            <apex:commandButton styleClass="Button" value="GoBack" action="{!goback}" />
           </apex:pageBlock>
           
        </apex:outputPanel>
            </apex:form>
</apex:page>
 
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


trigger SendEmailUser on Opportunity (after insert,after update) {
   
    Set<Id> setResource=new Set<Id>();
    Set<Id> setjob=new Set<Id>();
    List<NewJob__c> LatestJob=new List<NewJob__c>();
    for(Opportunity opp:Trigger.new){
        if(opp.Status__c == 'new'){
            if(opp.Resource__c != null ){
                setResource.add(opp.Resource__c);
              //  setjob.add(opp.Job__c);
            }
        }
    }
   
    List<String> lstEmails=new List<String>();
    if(!setResource.isEmpty()){
        List<Resource__c> lstResource= [Select Id,Email__c from Resource__c Where Id IN : setResource];
        if(!lstResource.isEmpty())
        {
            for(Resource__c res:lstResource)
            {
                lstEmails.add(res.Email__c);
            }
        }
    }
  // Set<String> nid=new Set<String>();
   // LatestJob=[SELECT Id FROM NewJob__c ORDER BY LastModifiedDate LIMIT 1];
   
   
   
   
   
    String Body='';
    if(!setResource.isEmpty()){
        List<Job_Application__c> Joblist=[SELECT Id FROM Job_Application__c order by CreatedDate desc limit 1];
        if(!Joblist.isEmpty())
        {
            for(Job_Application__c job:Joblist){
                body=body+'https://ap2.salesforce.com/'+job.id+'\n';
            }
        }
    }
   
    if(!lstEmails.isEmpty()){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(lstEmails);  
        mail.setSubject('Job Alert'); 
        mail.setPlainTextBody(Body);
        mail.setHtmlBody(Body);
        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
    }

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


1 comment:

  1. Salesforce Service Cloud is about ensuring that businesses provide exceptional customer service. It's like having a virtual customer care team on hand 24 hours a day, seven days a week. Salesforce Service Cloud Implementation can be a challenging yet rewarding experience, but it is important to streamline their customer service operations, improve their agent productivity, and ultimately enhance their overall customer experience.

    With Salesforce Service Cloud Implementation, you can easily assist your businesses to leverage the power of Salesforce to achieve your business goals. Request a free consultation with an AblyPro expert to learn how Salesforce Service Cloud may help your company improve customer service and drive higher retention rates!

    ReplyDelete