• Mthobisi Ndlovu
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi Guys

I have requirement where I need to display a report on a VF page based on the selected fiscal year. However I am having difficulty doing so.

both my list and variable are not getting set. I don't know what could be the problem. This is my 3rd VF page so I am not that clued up them.

Also is there a way to validate if the list is null on the VF page. if it is null an error must be displayed. Thanks in advance for your assistance.

Code is below.

<apex:page controller="SkillsDevBBBEEScorecardController">
<apex:form id="form"> 
    <apex:pageBlock id="pBlock">
         <apex:outputLabel >Select Financial Year:</apex:outputLabel>
         <apex:selectList value="{!selectedValue}" multiselect="false" size="1" > 
            <apex:selectOptions value="{!FiscalYearOptions}" /> 
        </apex:selectList> 
        <apex:commandButton id="btn" value="Run Report" action="{!SelectedValue}" reRender="pBlock,ResultsPanel"/>
    </apex:pageBlock>
    <apex:pageBlock id="ResultsPanel" >
        <apex:pageBlockSection >
            <apex:facet name="header">
               <apex:outputText value="{!ReportTitle}"/>
            </apex:facet>
            <apex:pageBlockTable value="{!scorecardWeightingACIEmployees}" var="employees" columnsWidth="2%,70%,5%,5%,5%,5%,5%">          
                 <apex:column headerValue="#">
                    <apex:outputLabel value="{!employees.Description_Item_Number__c} ">
                    </apex:outputLabel> 
                 </apex:column>
                 <apex:column headerValue="Criteria">
                    <apex:outputLabel value="{!employees.Criteria__c}">
                    </apex:outputLabel>
                 </apex:column>
                 <apex:column headerValue="Weighting Points">
                    <apex:outputLabel value="{!employees.Weighting_Point__c}">
                    </apex:outputLabel>
                 </apex:column>
                 <apex:column headerValue="Compliance Target">
                    <apex:outputLabel value="{!employees.Compliance_Target__c}">
                    </apex:outputLabel>
                 </apex:column>
                  <apex:column headerValue="Percentage">
                     <apex:variable value="{!employeesAchievedPercentage}" var="emp">
                     </apex:variable>
                 </apex:column>
                 <apex:column headerValue="Points">
                    <apex:outputLabel value="0">
                    </apex:outputLabel>
                 </apex:column>
            </apex:pageBlockTable>  
        </apex:pageBlockSection>
    </apex:pageBlock>
   </apex:form>
</apex:page>
public with sharing class SkillsDevBBBEEScorecardController {
	
	private static final Integer PREVIOUS_FISCAL_YEARS = 5;
	
	public String selectedValue;
	public Decimal employeesAchievedPercentage {get; set;}
	public Decimal employeesAchievedPoints {get; set;}
	public List<B_BBEE_Scorecard_Weighting__c> scorecardWeightingACIEmployees{get; set;}
    public PageReference selectedValue() {
        return null;
    }	
    
    public SkillsDevBBBEEScorecardController() {
    	scorecardWeightingACIEmployees = new List<B_BBEE_Scorecard_Weighting__c>();
    	scorecardWeightingACIEmployees = getScorecardWeightingACIEmployees();
    }
	
	public List<SelectOption> getFiscalYearOptions() {
		List<SelectOption> options = new List<SelectOption>();
		List<String>  selectOptionValues = UtilFiscalYear.getFiscalYears(PREVIOUS_FISCAL_YEARS, null);
		String firstOption = '--None--';
		options.add(new SelectOption('',firstOption));
		for (String option: selectOptionValues) {
		  	options.add(new SelectOption(option,option));
		}
		
		 return options;
	}
	public String getReportTitle() {
		String title = null;
		if (selectedValue != null) {
			title = 'Skills Development B-BBEE Scorecard Report for '+selectedValue;
		}
		return title;
	}	
	public String getSelectedValue() {
        return selectedValue;
    }
 
   public void setSelectedValue(String selected) {
       System.Debug('Set selectedValue ------>>>>>>>>: ' + selected);
        this.selectedValue = selected;
    }
	
	public Decimal getEmployeesAchievedPercentage() {
		return employeesAchievedPercentage;
	}
	
	public void setEmployeesAchievedPercentage(String selectVal) {
		System.Debug('employeesAchievedPercentage ------>>>>>>>>: ' +selectedValue);
		this.employeesAchievedPercentage = BBBEEScorecardService.calculateTargetAchievedPercentageForACIEmployees(Integer.valueOf(selectedValue));	
	}
	
	public List<B_BBEE_Scorecard_Weighting__c> getScorecardWeightingACIEmployees() {
			 System.Debug('List Display selectedValue ------>>>>>>>>: ' +selectedValue);
			if (scorecardWeightingACIEmployees == null) {
				scorecardWeightingACIEmployees = BBBEEScorecardWeightingSelector.findWeightingForACIEmployeesByFiscalYear(Integer.valueOf(selectedValue));
			}
			return scorecardWeightingACIEmployees;
	}
}

please let me know if you need any clarity.

I am having issues with Regex on apex.

I am trying to have a method to dynamically replace place holders in a string, example of placeholder : [COW_NAME] and an example of string(message) :
"Cow [COW_NAME] Signs of heat: Check cows vulva for clear discharge and change of colour of vulva lips from pink to red. Check every day of heat week."

My first issue was that even if I found a match instead of having the placeholder replaced by a cow name, the whole string would get replaced.

the first Regex: \\b.*[COW_NAME]\\b.* , match is found but the whole string is replaced
the second rege: \\[COW_NAME\\] didn't work no match was found at all.
I have only used Regex on Javascript a few times but  we all know JScript is different from Java.

public String replacePromptPlaceholder(ServiceData serviceData) {		
 String livestockValue;
 String replacedMessage = serviceData.message;
		
 if (serviceData.hasAPromptThatRequiresSubstitution()) {
	String message = serviceData.message;
	List<Template_Matcher__c> promptTemplateMatcherList = getPromptTemplateMatchers();
	if (promptTemplateMatcherList != null) {
	   for (Template_Matcher__c promptTemplate : promptTemplateMatcherList) {
		Pattern regexPattern = Pattern.compile(promptTemplate.Prompt_Regex__c);
		Matcher regexMatcher = regexPattern.matcher(message);
		if (regexMatcher.matches() == true) {
	        livestockValue = getLivestockPlaceholderValue(promptTemplate, serviceData.livestock);
	replacedMessage = message.replaceAll(promptTemplate.Prompt_Regex__c, livestockValue);
		    }
		}
	   }
	}
	return replacedMessage;
}

private static String getLivestockPlaceholderValue(Template_Matcher__c template, Livestock__c livestock ) {
 String livestockFieldValue = null;
 Object value = livestock.get(template.Field_Name__c);
 if (value != null) {
    livestockFieldValue =  String.valueOf(value);
	}
  return livestockFieldValue;
}

I am not sure if my code is wrong or it's my regex. Please assist
I have a trigger that has to delete an Account record associated with a Contact record when that particular contact  record gets deleted, However I get the following error when the DML  statement delete get's executed.

"15:14:59:227 FATAL_ERROR System.DmlException: Delete failed. First exception on row 0 with id 0011100000R5Gf0AAF; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0031100000QId7U) is currently in trigger deleteAccountRecord, therefore it cannot recursively delete itself: []"

here is my code: 

trigger deleteAccountRecord on Contact (before delete) {


    RecordType donorRecType = [SELECT ID FROM RecordType WHERE sObjectType = 'Contact' AND DeveloperName = 'Donor_Contact'];
    if(Trigger.isDelete){
        List<ID> contactIDList = new List<ID>();
        for(Contact contactToDelete: Trigger.old) {
            if (contactToDelete.RecordTypeId != donorRecType.Id ) {
                  
                    contactIDList.add(contactToDelete.id);
            }
        }
      
       
       List<Account> DelAccountRecordList = [select id from Account where Id IN(SELECT accountId FROM Contact WHERE Id IN :contactIDList)];

        if(DelAccountRecordList.size() >0 && RecursiveTriggerHelper.isFirstRun){
           RecursiveTriggerHelper.isFirstRun = false;
           delete DelAccountRecordList ;
         
        }
     }
  }

//Helps to stop the trigger from firing twice. (at least It should but it's not working)
public class RecursiveTriggerHelper {

     public static boolean isFirstRun = true;
  
}

I have tried using "After Insert" but DelAccountRecordList returns null with no records. Is there a way to deal with my error without changing "Before Update". I am totally out of ideas on how to solve this issue.

Thanks in advance for your help.
I am having issues with Regex on apex.

I am trying to have a method to dynamically replace place holders in a string, example of placeholder : [COW_NAME] and an example of string(message) :
"Cow [COW_NAME] Signs of heat: Check cows vulva for clear discharge and change of colour of vulva lips from pink to red. Check every day of heat week."

My first issue was that even if I found a match instead of having the placeholder replaced by a cow name, the whole string would get replaced.

the first Regex: \\b.*[COW_NAME]\\b.* , match is found but the whole string is replaced
the second rege: \\[COW_NAME\\] didn't work no match was found at all.
I have only used Regex on Javascript a few times but  we all know JScript is different from Java.

public String replacePromptPlaceholder(ServiceData serviceData) {		
 String livestockValue;
 String replacedMessage = serviceData.message;
		
 if (serviceData.hasAPromptThatRequiresSubstitution()) {
	String message = serviceData.message;
	List<Template_Matcher__c> promptTemplateMatcherList = getPromptTemplateMatchers();
	if (promptTemplateMatcherList != null) {
	   for (Template_Matcher__c promptTemplate : promptTemplateMatcherList) {
		Pattern regexPattern = Pattern.compile(promptTemplate.Prompt_Regex__c);
		Matcher regexMatcher = regexPattern.matcher(message);
		if (regexMatcher.matches() == true) {
	        livestockValue = getLivestockPlaceholderValue(promptTemplate, serviceData.livestock);
	replacedMessage = message.replaceAll(promptTemplate.Prompt_Regex__c, livestockValue);
		    }
		}
	   }
	}
	return replacedMessage;
}

private static String getLivestockPlaceholderValue(Template_Matcher__c template, Livestock__c livestock ) {
 String livestockFieldValue = null;
 Object value = livestock.get(template.Field_Name__c);
 if (value != null) {
    livestockFieldValue =  String.valueOf(value);
	}
  return livestockFieldValue;
}

I am not sure if my code is wrong or it's my regex. Please assist
I have a trigger that has to delete an Account record associated with a Contact record when that particular contact  record gets deleted, However I get the following error when the DML  statement delete get's executed.

"15:14:59:227 FATAL_ERROR System.DmlException: Delete failed. First exception on row 0 with id 0011100000R5Gf0AAF; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 0031100000QId7U) is currently in trigger deleteAccountRecord, therefore it cannot recursively delete itself: []"

here is my code: 

trigger deleteAccountRecord on Contact (before delete) {


    RecordType donorRecType = [SELECT ID FROM RecordType WHERE sObjectType = 'Contact' AND DeveloperName = 'Donor_Contact'];
    if(Trigger.isDelete){
        List<ID> contactIDList = new List<ID>();
        for(Contact contactToDelete: Trigger.old) {
            if (contactToDelete.RecordTypeId != donorRecType.Id ) {
                  
                    contactIDList.add(contactToDelete.id);
            }
        }
      
       
       List<Account> DelAccountRecordList = [select id from Account where Id IN(SELECT accountId FROM Contact WHERE Id IN :contactIDList)];

        if(DelAccountRecordList.size() >0 && RecursiveTriggerHelper.isFirstRun){
           RecursiveTriggerHelper.isFirstRun = false;
           delete DelAccountRecordList ;
         
        }
     }
  }

//Helps to stop the trigger from firing twice. (at least It should but it's not working)
public class RecursiveTriggerHelper {

     public static boolean isFirstRun = true;
  
}

I have tried using "After Insert" but DelAccountRecordList returns null with no records. Is there a way to deal with my error without changing "Before Update". I am totally out of ideas on how to solve this issue.

Thanks in advance for your help.