Skip to content

Instantly share code, notes, and snippets.

@lindon-fox
Created March 18, 2013 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindon-fox/5185579 to your computer and use it in GitHub Desktop.
Save lindon-fox/5185579 to your computer and use it in GitHub Desktop.
Strange logging on Salesforce
public void doSearch() {
System.debug('mgical fun');
System.debug('mgical fun3');
System.debug('mgical fun4');
System.debug('mgical fun5');
System.debug('mgical fun 2-');
System.debug('mgical fun 2');
System.debug('mgical fun 2');
System.debug('mgical fun 2');
System.debug('mgical fun 2');
System.debug('mgical fun 2');
System.debug('mgical fun 2-');
page = 0;//reset page number as this is a new search
this.summaryList.clear();
this.searchResultList.clear();
this.viewResults.clear();
System.debug('mgical fun6');
if(this.validate()){
System.debug('mgical fun7');
String sql =
'SELECT ' +
' aped.Office__c, aped.Name__c, aped.Code__c, aped.UserId__c, aped.OfficeCode__c, aped.PlanId__c ' +
'FROM ' +
' PlanAll__c aped ' +
'WHERE ' +
' aped.id <> null ' + getSearchCond() + ' ' +
'ORDER BY aped.OfficeCode__c';
this.debug_sql = sql;
List<PlanAll__c> planAllList = Database.query(sql);
List<String> planAllIdList = new List<String>();
for(PlanAll__c planAllItem : planAllList){
planAllIdList.add(planAllItem.ID);
}
System.debug('WHAT IS GOING ON HERE?');
sql =
'SELECT ' +
' sp.Id, sp.Actual__c, sp.Status__c, sp.planAllId__c, sp.Status__c, sp.Point__c, aped.Office__c, aped.OfficeCode__c ' +
'FROM ' +
' Progress__c sp, ' +
' Progress__c.PlanAllId__r aped ' +
'WHERE ' +
' sp.id <> null ' +
'AND sp.planAllId__c in :planAllIdList ' +
'ORDER BY aped.OfficeCode__c';
this.debug_sql += '\t\t\t\t\t\t\t\t\t\t\t\t' + sql;
List<Progress__c> progressList = Database.query(sql);//new List<Progress__c>();
System.debug('HELLOOOOOO');
sql =
'SELECT ' +
' a.id ' +
'FROM ' +
' Account a ' +
'WHERE ' +
' a.Office__c in :planAllIdList ';
List<Account> accountList = Database.query(sql);
System.Debug('HELLOOOOOO');
System.Debug('-THIS IS HTE ONE SUMMARY makeCalculations planAllList size: ' + planAllList.size());
for(PlanAll__c planAllItem : planAllList){
SummaryWrapper wrapper = new SummaryWrapper(planAllItem, progressList);
System.Debug('THIS IS HTE ONE makeCalculations ' + planAllItem);
wrapper.makeCalculations(accountList);
searchResultList.add(wrapper);
}
for(SummaryWrapper wrapper : searchResultList){
Boolean foundMatch = false;
SummaryWrapper newSummaryWrapper = null;
for (SummaryWrapper summaryWrapper : summaryList) {
if(wrapper.wrappersMatch(summaryWrapper)){
newSummaryWrapper = summaryWrapper;
}
}
if(newSummaryWrapper == null){
//we have still not found the wrapper, so lets make a new one...
List<Progress__c> newProgressList = new List<Progress__c>();
newProgressList.addAll(wrapper.progressList);
//summaryList
newSummaryWrapper = new SummaryWrapper(wrapper.planAllItem, newProgressList);
summaryList.add(newSummaryWrapper);
}
else{
newSummaryWrapper.addToWrapper(wrapper);
}
}
testOutput = '-THIS IS HTE ONE SUMMARY makeCalculations size:';
System.Debug('-THIS IS HTE ONE SUMMARY makeCalculations size: ' + summaryList.size());
testOutput = '-THIS IS HTE ONE SUMMARY makeCalculations size:2';
for(SummaryWrapper wrapper : summaryList){
System.Debug('THIS IS HTE ONE SUMMARY makeCalculations ' + wrapper);
//commenting out this line (and the other call to this method above, will stop the strange behaviour...
wrapper.makeCalculations(accountList);
}
this.showResult = true;
}
else{
System.debug('mgical fun8');
this.showResult = false;
}
this.bindView();
System.debug('mgical fun 22-');
System.debug('mgical fun 22');
System.debug('mgical fun 22');
System.debug('mgical fun 22');
System.debug('mgical fun 22-');
}
public with sharing class SummaryWrapper{
public PlanAll__c planAllItem {get;set;}
public List<Progress__c> progressList {get;set;}
public SummaryCalculations calculations {get;set;}
public Boolean navigatable {get;set;}
public SummaryWrapper(PlanAll__c planAllItem, List<Progress__c> progressList){
this.planAllItem = planAllItem;
this.progressList = new List<Progress__c>();
System.debug('HAIR CARE POWER PREPERATION* ' + progressList.size());
for(Progress__c solutionProgress : progressList){
if(solutionProgress.planAllId__c == this.planAllItem.ID){
this.progressList.add(solutionProgress);
}
}
navigatable = this.progressList.size() > 0;
navigatable = true;
}
public void makeCalculations(List<Account> accountList){
this.calculations = new SummaryCalculations(this, accountList);
}
public Boolean wrappersMatch(SummaryWrapper additionalWrapper){
return this.planAllItem.Office__c.equals(additionalWrapper.planAllItem.Office__c);
}
public void addToWrapper(SummaryWrapper additionalWrapper){
System.assertEquals(this.planAllItem.Office__c, additionalWrapper.planAllItem.Office__c);
this.progressList.addAll(additionalWrapper.progressList);
}
}
public with sharing class SummaryCalculations{
public SummaryCalculations(SummaryWrapper wrapper, List<Account> accountList){
// this.mainMatchCount = 'TODO';
System.debug('THIS IS HTE ONE ' + accountList.size());
Decimal mainMatchCountCounter = 0;
for(Account account : accountList){
System.debug('THIS IS HTE account we are looking at: ' + account);
System.debug('THIS IS HTE wrapper we are looking from: ' + wrapper);
if(account.OfficeCode__c == wrapper.planAllItem.OfficeCode__c && account.Code__c == wrapper.planAllItem.Code__c){
System.debug('THIS IS HTE WE GOT IT');
mainMatchCountCounter += 1;
}
}
Decimal goalPointSumCounter = 0;
Decimal prospectPointSumCounter = 0;
Decimal actualPointSumCounter = 0;
Integer proposalCalculationCount = 0;
Integer projectCount = 0;
Integer preperationCount = 0;
Integer practiceOneCount = 0;
Integer practiceTwoCount = 0;
Integer practiceThreeCount = 0;
Integer verificationCount = 0;
String status = '';
String solutionKbn = '';
System.debug('HAIR CARE: ' + wrapper.progressList.size());
for(Progress__c solutionProgress : wrapper.progressList){
goalPointSumCounter += solutionProgress.Point__c;
actualPointSumCounter += solutionProgress.Actual__c;
status = solutionProgress.Status__c;
if('one'.equals(status)){
proposalCalculationCount += 1;
}
else if('two'.equals(status)){
projectCount += 1;
}
else if('three'.equals(status)){
preperationCount += 1;
}
else if('four'.equals(status)){
practiceOneCount += 1;
}
else if('five'.equals(status)){
practiceTwoCount += 1;
}
else if('six'.equals(status)){
practiceThreeCount += 1;
}
else if('seven'.equals(status)){
verificationCount += 1;
}
else{
System.debug('Coulnd not find a match for the status: ' + status);
}
this.newServiceShop = NO_STATUS_VALUE;
this.newServiceShopLinkSolutionProgress = null;
this.existingServiceShip = NO_STATUS_VALUE;
this.existingServiceShipSolutionProgress = null;
this.lpShop = NO_STATUS_VALUE;
this.lpShopSolutionProgress = null;
this.outOfBoundsCallDeployment = NO_STATUS_VALUE;
this.outOfBoundsCallDeploymentSolutionProgress = null;
this.outOfBoundsCallInHouse = NO_STATUS_VALUE;
this.outOfBoundsCallInHouseSolutionProgress = null;
this.existingContractCall = NO_STATUS_VALUE;
this.existingContractCallSolutionProgress = null;
this.organisationMarket = NO_STATUS_VALUE;
this.organisationMarketSolutionProgress = null;
this.newContactUse = NO_STATUS_VALUE;
this.newContactUseSolutionProgress = null;
this.existingContactEducation = NO_STATUS_VALUE;
this.existingContactEducationSolutionProgress = null;
this.corporateProjectSuccession = NO_STATUS_VALUE;
this.corporateProjectSuccessionSolutionProgress = null;
solutionKbn = '' + solutionProgress.Status__c;
if('1'.equals(solutionKbn)){
//todo need to update this so we are getting the Status__c instead
this.newServiceShopLinkSolutionProgress = solutionProgress;
this.newServiceShop = solutionProgress.Status__c;
}
else if('2'.equals(solutionKbn)){
this.existingServiceShip = solutionProgress.Status__c;
this.existingServiceShipSolutionProgress = solutionProgress;
}
else if('3'.equals(solutionKbn)){
this.lpShop = solutionProgress.Status__c;
this.lpShopSolutionProgress = solutionProgress;
}
else if('4'.equals(solutionKbn)){
this.outOfBoundsCallDeployment = solutionProgress.Status__c;
this.outOfBoundsCallDeploymentSolutionProgress = solutionProgress;
}
else if('5'.equals(solutionKbn)){
this.outOfBoundsCallInHouse = solutionProgress.Status__c;
this.outOfBoundsCallInHouseSolutionProgress = solutionProgress;
}
else if('6'.equals(solutionKbn)){
this.existingContractCall = solutionProgress.Status__c;
this.existingContractCallSolutionProgress = solutionProgress;
}
else if('7'.equals(solutionKbn)){
this.organisationMarket = solutionProgress.Status__c;
this.organisationMarketSolutionProgress = solutionProgress;
}
else if('8'.equals(solutionKbn)){
this.newContactUse = solutionProgress.Status__c;
this.newContactUseSolutionProgress = solutionProgress;
}
else if('9'.equals(solutionKbn)){
this.existingContactEducation = solutionProgress.Status__c;
this.existingContactEducationSolutionProgress = solutionProgress;
}
else if('10'.equals(solutionKbn)){
this.corporateProjectSuccession = solutionProgress.Status__c;
this.corporateProjectSuccessionSolutionProgress = solutionProgress;
}
else if('default'.equals(solutionKbn)){
//we are expecting this...
}
else{
System.debug('Coulnd not find a match for the solutionKbn: ' + solutionKbn);
}
}
this.mainMatchCount = '' + mainMatchCountCounter.toPlainString();
System.debug('HELLO MR RUCKY 0- -THIS IS HTE ONE SUMMARY makeCalculations size:');
System.debug('HELLO MR RUCKY 1- -THIS IS HTE ONE SUMMARY makeCalculations size:');
this.goalPointSum = '' + goalPointSumCounter.toPlainString();
System.debug('HELLO MR RUCKY 2- -THIS IS HTE ONE SUMMARY makeCalculations size:');
this.prospectPointSum = '' + prospectPointSumCounter.toPlainString();
this.actualPointSum = '' + actualPointSumCounter.toPlainString();
if(goalPointSumCounter == 0){
//we don't want to divide by zero, that is dangerous stuff...
this.progressOverActual = NO_STATUS_VALUE;
}
else{
this.progressOverActual = '' + (Math.floor(actualPointSumCounter / goalPointSumCounter) *100) + '%';//flooring the division....
}
this.proposalCalculation = '' + proposalCalculationCount;
this.project = '' + projectCount;
this.preperation = '' + preperationCount;
this.practiceOne = '' + practiceOneCount;
this.practiceTwo = '' + practiceTwoCount;
this.practiceThree = '' + practiceThreeCount;
this.verification = '' + verificationCount;
}
public String mainMatchCount {get;set;}
public String goalPointSum {get;set;}//both tables
public String prospectPointSum {get;set;}
public String actualPointSum {get;set;}//both tables
public String progressOverActual {get;set;}
public String proposalCalculation {get;set;}
public String project {get;set;}
public String preperation {get;set;}
public String practiceOne {get;set;}
public String practiceTwo {get;set;}
public String practiceThree {get;set;}
public String verification {get;set;}
public String newServiceShop {get;set;}
public Progress__c newServiceShopLinkSolutionProgress {get;set;}
public String existingServiceShip {get;set;}
public Progress__c existingServiceShipSolutionProgress {get;set;}
public String lpShop {get;set;}
public Progress__c lpShopSolutionProgress {get;set;}
public String outOfBoundsCallDeployment {get;set;}
public Progress__c outOfBoundsCallDeploymentSolutionProgress {get;set;}
public String outOfBoundsCallInHouse {get;set;}
public Progress__c outOfBoundsCallInHouseSolutionProgress {get;set;}
public String existingContractCall {get;set;}
public Progress__c existingContractCallSolutionProgress {get;set;}
public String organisationMarket {get;set;}
public Progress__c organisationMarketSolutionProgress {get;set;}
public String newContactUse {get;set;}
public Progress__c newContactUseSolutionProgress {get;set;}
public String existingContactEducation {get;set;}
public Progress__c existingContactEducationSolutionProgress {get;set;}
public String corporateProjectSuccession {get;set;}
public Progress__c corporateProjectSuccessionSolutionProgress {get;set;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment