• ponneri navadeep
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 5
    Replies
public class Core_IPS_Case_List_View_Export { 

    public static final integer MAX_EXPORT_ROWS = 10000;

    public Boolean isPDFExportActive { get; set; }

    public Boolean isExcelExportActive { get; set; }

    public String contentType { get; set; } 

    public String renderType { get; set; }

    public List<List<Case>> lstlstCase { get; set; }

    public String reportDate { get; set; }

    public String filterName { get; set; }

    private List<Case> lstCase;
    private String returnURL;
    private ApexPages.StandardSetController sscController;

    public Core_IPS_Case_List_View_Export(ApexPages.StandardSetController controller) {

        System.debug('#01 controller.getResultSize(): ' + controller.getResultSize());

        returnURL = ApexPages.CurrentPage().getUrl();

        // For Excel:
        contentType = 'application/vnd.ms-excel#Cases.xls';
        renderType  = '';

        // For PDF:
        // contentType = 'application/pdf#Cases.pdf';
        // renderType  = 'PDF';

        Datetime dtNow = Datetime.now();
        reportDate = dtNow.format('yyyy-MM-dd h:mm a');

        sscController = controller;
        sscController.setPageSize(1000);

        lstlstCase = new List<List<Case>>();
        
        String strfilterId = sscController.getFilterId();
        List<System.SelectOption> lstSelectOption = sscController.getListViewOptions();
        for (System.SelectOption so : lstSelectOption)
            if (so.getValue() == strfilterId) { 
                filterName = so.getLabel();            
                break;
            }

        isPDFExportActive   = false;
        isExcelExportActive = (sscController.getResultSize() < MAX_EXPORT_ROWS);

        System.debug('#01 sscController.getResultSize(): ' + sscController.getResultSize());
        if (sscController.getResultSize() >= MAX_EXPORT_ROWS) { 
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, 'Maximum export size of ' + MAX_EXPORT_ROWS + ' cases exceeded.');
            ApexPages.addMessage(myMsg);
        }            
        
    }
    
    
    public PageReference returnToPage() {
    
        PageReference returnPage;
    
        Boolean portalUser = Core_IPS_Case_Comments_Handler.isCurrentUserPortalUser();
        if (portalUser)                    
            returnPage = new PageReference('/IPS/500/o');
        else    
            returnPage = new PageReference('/500/o');
            
        returnPage.setRedirect(true);
        return returnPage;
    }      
    
    
    private void loadCaseData() {
        Set<Id> setCaseId = new Set<Id>();                
        while(true) {
                
            for(Case cs : (List<Case>)sscController.getRecords())
                setCaseId.add(cs.Id);
            System.debug('#02 setCaseId: ' + setCaseId);

            lstCase = [SELECT Id, CaseNumber, Account.Name, Core_IPS_Project_Case__r.Name, Contact.Name, 
                              Subject, Status, Core_Sub_Status__c, Core_Severity__c, Product.Name, 
                              CreatedDate, LastModifiedDate, Core_IPS_Legacy_IPS_ID__c                               
                       FROM Case 
                       WHERE Id IN :setCaseId
                       ORDER BY CaseNumber];           

            lstlstCase.add(lstCase);

            if (lstlstCase.size() == 10)
                break;

            if (!sscController.getHasNext())
                break;
                
            setCaseId.clear();
            sscController.next();
        }     
    }
    
    public PageReference exportToExcel() {

        try {
            loadCaseData();
        }
        catch (Exception e) {
            String consolidatedMessage = e.getTypeName() + ' on line# ' + e.getLineNumber() + ' : ' + e.getMessage();
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, consolidatedMessage);
            ApexPages.addMessage(myMsg);
            return null;
        }

        PageReference excelPage = page.Core_IPS_Case_List_View;
        excelPage.setRedirect(false);
        return excelPage;
    }      
    
}
  1. The line of code:

The users are making the wrong selection and then proceeding to fill out the form and save the question and then they realize
they’re in the wrong section.  There’s no way for them to change the record type once selected.
 
I’ve setup the skeleton of a Custom Button and a Visualforce page that you will program to provide the user the opportunity
to change the record type.
 
Your first objective will be to add a drop down list to the visualforce page and load it with the possible records  type
for the Core_Ask_A_Question__c object.
 
You can read the record types using the Schema IPA, and from that you’ll get a list of record types.  Load the available record types
into the drop down list.  There’s more – and I’ll provide the rest shortly.
 
I set up a skeleton consisting of the following artifacts:
 
 
 
  objAAQ = (Core_Ask_A_Question__c) controller.getRecord();
 
This get’s the AAQ record that the user is currently looking at when they pressed the “Change Record Type” button.
Get the record type from objAAQ and only show, in the drop down list, those record types that aren’t the same
as the record type of the current record.  Right now there’s only one other choice, but in the future, there will be more.
You can even auto-populate the new record type field if there’s only one selection available.
 
  1. Add a “Save” button.
 
  1. When the user presses “Save”, use the Schema API to get the fields for the AAQ record and select the fields that have picklists.
 
Requirement:  Make sure that the picklist selections in the picklist fields are still available in the new record type.
 
You’ll have to use the Schema API to get the picklist values for the new record type, and then compare them
with the values entered on the AAQ record to make sure that they are still valid.  If the value is longer supported
by the new record type, blank it out on the objAAQ variable.
 
 
global class Core_IPS_Entitlement_For_Migrated_Cases implements Database.Batchable<sObject>{

        global Core_IPS_Entitlement_For_Migrated_Cases(){
                   // Batch Constructor
                   
                    
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator([Select id,status,Core_Next_Response_Due_Date__c,BusinessHoursId,AccountId,SlaStartDate,Core_First_Response_Completed__c,SlaExitDate,ContactId,EntitlementID,Core_IPS_Legacy_IPS_ID__c,Core_IPS_GEC_Flag__c from Case where status='Open' And Core_IPS_GEC_Flag__c = false AND Core_IPS_Legacy_IPS_ID__c != Null and recordType.name='IPS Case Create' AND Core_IPS_GEC_Case__c =false Limit 2]);
        //return Database.getQueryLocator([Select id,status,Core_Next_Response_Due_Date__c,BusinessHoursId,AccountId,SlaStartDate,Core_First_Response_Completed__c,SlaExitDate,ContactId,EntitlementID,Core_IPS_Legacy_IPS_ID__c,Core_IPS_GEC_Flag__c from Case where id='50021000000gVKH']);

        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise    
             /*List<case> LstCase =  new List<case>();
            for(sobject s : scope){
            Case c = (case)s;
            system.debug(c);
            LstCase.add(c); 
            }*/
            Core_IPS_CaseTriggerHandler.assignEntitlementToCase(scope);
            //complteActiveMilstone 
            
            //update scope;
            
            for(sobject s : scope){
                Case cs = (case)s;
                if(!cs.Core_First_Response_Completed__c) cs.Core_First_Response_Completed__c=true;
                cs.Core_Next_Response_Due_Date__c = system.now() + 7;
             }
            update scope;
            
            Map<Id,List<CaseMilestone>> CaseMilestoneByCaseId = milestoneUtils.getActiveMileStone(scope);
            List<CaseMilestone> LstCaseMilestoneToUpdate = new List<CaseMilestone>();
            for(sobject s : scope){
            Case cs = (case)s;
            
            //if (milestoneUtils.isCaseMilestoneUpdateRequired(cs, system.now())){
                //cs.Core_Trigger_Next_Response__c=true;
                /*if(!cs.Core_First_Response_Completed__c) milestoneUtils.completeMilestone(cs, mtFst.name, completionDate);
                else milestoneUtils.completeMilestone(cs, mtNxt.name, completionDate);*/
                List<CaseMileStone> milestoneList = CaseMilestoneByCaseId.get(cs.id);
                if(milestoneList !=null)
                {
                if(milestoneList.size()>1){
                }else{
                
                    milestoneList[0].completionDate = system.now() ;
                    LstCaseMilestoneToUpdate.add(milestoneList[0]);
                    //System.debug('Complete DATE : ' + completionDate );
                    //update milestoneList[0];
                }
              }
            //LstCase.add(c); 
            //}
            }
            if(LstCaseMilestoneToUpdate.size() > 0)
            {
                update LstCaseMilestoneToUpdate;
            }
            
            
        }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }

 



User-added image






  try{
            String query = '';
            DateTime lastRunDateTime = AccountTeamBatchHandler.getLastRunDateTime('Core_IPS_AccountTeamUpdate_Scheduler');
            if(lastRunDateTime!=null)
                batchProcessing.Core_Last_Run_Date__c = lastRunDateTime;
            if(Test.isRunningTest()){
                query = 'select id from Account where id in(select accountid from accountshare where lastmodifieddate >= TODAY)';
            }else if(lastRunDateTime!=null){
                batchProcessing.Core_Start_Date_Time__c = system.Now();
                query = 'select id from Account where id in(select accountid from accountshare where lastmodifieddate >= :lastRunDateTime and rowcause=\'Team\')';
            }else{
                throw new BatchException('Core_IPS_AccountTeamUpdate_Scheduler not started as Lasr Run Batch Time is not specified');
            }
            batchProcessing.Batch_Header__C = header.id;
            batchProcessing.Core_Salesforce_Job_Id__c = BC.getJobId();
            batchProcessing.Core_Batch_Query__c = query;
            batchProcessing.Core_Email_Distribution_List__c=header.Email_Distribution_List__c;
            batchProcessing.Core_Object_Name__c = 'Account';
            insert batchProcessing;
User-added image
how can i cover the code for red lines?

 
User-added image
how can i cover the code for red lines?

 
global class Core_IPS_Entitlement_For_Migrated_Cases implements Database.Batchable<sObject>{

        global Core_IPS_Entitlement_For_Migrated_Cases(){
                   // Batch Constructor
                   
                    
        }
       
        // Start Method
        global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator([Select id,status,Core_Next_Response_Due_Date__c,BusinessHoursId,AccountId,SlaStartDate,Core_First_Response_Completed__c,SlaExitDate,ContactId,EntitlementID,Core_IPS_Legacy_IPS_ID__c,Core_IPS_GEC_Flag__c from Case where status='Open' And Core_IPS_GEC_Flag__c = false AND Core_IPS_Legacy_IPS_ID__c != Null and recordType.name='IPS Case Create' AND Core_IPS_GEC_Case__c =false Limit 2]);
        //return Database.getQueryLocator([Select id,status,Core_Next_Response_Due_Date__c,BusinessHoursId,AccountId,SlaStartDate,Core_First_Response_Completed__c,SlaExitDate,ContactId,EntitlementID,Core_IPS_Legacy_IPS_ID__c,Core_IPS_GEC_Flag__c from Case where id='50021000000gVKH']);

        }
      
      // Execute Logic
       global void execute(Database.BatchableContext BC, List<sObject>scope){
              // Logic to be Executed batch wise    
             /*List<case> LstCase =  new List<case>();
            for(sobject s : scope){
            Case c = (case)s;
            system.debug(c);
            LstCase.add(c); 
            }*/
            Core_IPS_CaseTriggerHandler.assignEntitlementToCase(scope);
            //complteActiveMilstone 
            
            //update scope;
            
            for(sobject s : scope){
                Case cs = (case)s;
                if(!cs.Core_First_Response_Completed__c) cs.Core_First_Response_Completed__c=true;
                cs.Core_Next_Response_Due_Date__c = system.now() + 7;
             }
            update scope;
            
            Map<Id,List<CaseMilestone>> CaseMilestoneByCaseId = milestoneUtils.getActiveMileStone(scope);
            List<CaseMilestone> LstCaseMilestoneToUpdate = new List<CaseMilestone>();
            for(sobject s : scope){
            Case cs = (case)s;
            
            //if (milestoneUtils.isCaseMilestoneUpdateRequired(cs, system.now())){
                //cs.Core_Trigger_Next_Response__c=true;
                /*if(!cs.Core_First_Response_Completed__c) milestoneUtils.completeMilestone(cs, mtFst.name, completionDate);
                else milestoneUtils.completeMilestone(cs, mtNxt.name, completionDate);*/
                List<CaseMileStone> milestoneList = CaseMilestoneByCaseId.get(cs.id);
                if(milestoneList !=null)
                {
                if(milestoneList.size()>1){
                }else{
                
                    milestoneList[0].completionDate = system.now() ;
                    LstCaseMilestoneToUpdate.add(milestoneList[0]);
                    //System.debug('Complete DATE : ' + completionDate );
                    //update milestoneList[0];
                }
              }
            //LstCase.add(c); 
            //}
            }
            if(LstCaseMilestoneToUpdate.size() > 0)
            {
                update LstCaseMilestoneToUpdate;
            }
            
            
        }
     
       global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
       }
    }

 
User-added image
how can i cover the code for red lines?