You need to sign in to do that
Don't have an account?
sumit d
trigger to update a custom field quality score
Hi All,
my requirement is to count the % of quality score when a new account is inserted or updated Account.
i created a map According to record type .And inside it a map for fields and thier scoring.but its not calculating the value of Quality score.
Can you help me out with this trigger?
public without sharing class AccountTriggerHelper {
public static List<Account> newAccount = new List<Account>();
public static List<Account> oldAccount = new List<Account>();
public static Map<Id, Account> newMapAccount = new Map<Id, Account>();
public static Map<Id, Account> oldMapAccount = new Map<Id, Account>();
public static boolean runTrigger = TRUE;
public static Map<String, Map<String, Integer>> mapRecordTypeToScores = new Map<String, Map<String, Integer>> {
'Cachet' => new Map<String, Integer> {
'ACH_Provider__c' => 5,
'Payroll_Software__c' => 3,
'HR_Software__c' => 3,
'Payroll_Tax_Processor__c' => 3,
'Current_Bank__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'Time_Attendance__c' => 2,
'CPA_Accounting_Firm__c' => 2
},
'Time_Rack' => new Map<String, Integer> {
'Time_Attendance__c' => 5,
'CPA_Accounting_Firm__c' => 3,
'Payroll_Software__c' => 3,
'Current_Bank__c' => 3,
'HR_Software__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'ACH_Provider__c' => 2,
'Payroll_Tax_Processor__c' => 2
},
'PTM' => new Map<String, Integer> {
'Payroll_Tax_Processor__c' => 5,
'ACH_Provider__c' => 3,
'Payroll_Software__c' => 3,
'Current_Bank__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'Time_Attendance__c' => 2,
'HR_Software__c' => 2,
'CPA_Accounting_Firm__c' => 2
},
'SBS' => new Map<String, Integer> {
'Payroll_Software__c' => 5,
'ACH_Provider__c' => 3,
'Payroll_Tax_Processor__c' => 3,
'Current_Bank__c' => 3,
'Time_Attendance__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'HR_Software__c' => 2,
'CPA_Accounting_Firm__c' => 2
}
};
//To update Quality Score Field on Account
public static void updateQualityScore(){
//Map<ID,Schema.RecordTypeInfo> rt_Map = Account.sObjectType.getDescribe().getRecordTypeInfosById();
// List<Account> accListToUpdate = new List<Account>();
for(Account acc : newAccount){
//Integer fieldValue = 0;
Integer totalScoreAchieved = 0;
Integer totalScorePossible = 0;
String recordTypeDeveloperName = acc.RecordType.developerName;
if( recordTypeDeveloperName != null ) {
Map<String, Integer> mapFieldAPINameToScore = mapRecordTypeToScores.get( recordTypeDeveloperName );
totalScoreAchieved = 0;
if( mapFieldAPINameToScore != null ) {
for( String fieldAPIName : mapFieldAPINameToScore.keySet() ) {
Object fieldValue = acc.get( fieldAPIName );
Integer scoreForTheField = mapFieldAPINameToScore.get( fieldAPIName );
totalScorePossible += scoreForTheField;
if( fieldValue != null && String.valueOf( fieldValue ) != 'Other' ) {
totalScoreAchieved += scoreForTheField;
}
}
}
if( totalScorePossible > 0 ) {
acc.Quality_Score__c = ( totalScoreAchieved * 100 ) / totalScorePossible;
}
//accListToUpdate.add( acc );
}
}
// update accListToUpdate;
}
what i am missing in it?
Any suggestions?
my requirement is to count the % of quality score when a new account is inserted or updated Account.
i created a map According to record type .And inside it a map for fields and thier scoring.but its not calculating the value of Quality score.
Can you help me out with this trigger?
public without sharing class AccountTriggerHelper {
public static List<Account> newAccount = new List<Account>();
public static List<Account> oldAccount = new List<Account>();
public static Map<Id, Account> newMapAccount = new Map<Id, Account>();
public static Map<Id, Account> oldMapAccount = new Map<Id, Account>();
public static boolean runTrigger = TRUE;
public static Map<String, Map<String, Integer>> mapRecordTypeToScores = new Map<String, Map<String, Integer>> {
'Cachet' => new Map<String, Integer> {
'ACH_Provider__c' => 5,
'Payroll_Software__c' => 3,
'HR_Software__c' => 3,
'Payroll_Tax_Processor__c' => 3,
'Current_Bank__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'Time_Attendance__c' => 2,
'CPA_Accounting_Firm__c' => 2
},
'Time_Rack' => new Map<String, Integer> {
'Time_Attendance__c' => 5,
'CPA_Accounting_Firm__c' => 3,
'Payroll_Software__c' => 3,
'Current_Bank__c' => 3,
'HR_Software__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'ACH_Provider__c' => 2,
'Payroll_Tax_Processor__c' => 2
},
'PTM' => new Map<String, Integer> {
'Payroll_Tax_Processor__c' => 5,
'ACH_Provider__c' => 3,
'Payroll_Software__c' => 3,
'Current_Bank__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'Time_Attendance__c' => 2,
'HR_Software__c' => 2,
'CPA_Accounting_Firm__c' => 2
},
'SBS' => new Map<String, Integer> {
'Payroll_Software__c' => 5,
'ACH_Provider__c' => 3,
'Payroll_Tax_Processor__c' => 3,
'Current_Bank__c' => 3,
'Time_Attendance__c' => 3,
'Payroll_Business_Consultant__c' => 2,
'HR_Software__c' => 2,
'CPA_Accounting_Firm__c' => 2
}
};
//To update Quality Score Field on Account
public static void updateQualityScore(){
//Map<ID,Schema.RecordTypeInfo> rt_Map = Account.sObjectType.getDescribe().getRecordTypeInfosById();
// List<Account> accListToUpdate = new List<Account>();
for(Account acc : newAccount){
//Integer fieldValue = 0;
Integer totalScoreAchieved = 0;
Integer totalScorePossible = 0;
String recordTypeDeveloperName = acc.RecordType.developerName;
if( recordTypeDeveloperName != null ) {
Map<String, Integer> mapFieldAPINameToScore = mapRecordTypeToScores.get( recordTypeDeveloperName );
totalScoreAchieved = 0;
if( mapFieldAPINameToScore != null ) {
for( String fieldAPIName : mapFieldAPINameToScore.keySet() ) {
Object fieldValue = acc.get( fieldAPIName );
Integer scoreForTheField = mapFieldAPINameToScore.get( fieldAPIName );
totalScorePossible += scoreForTheField;
if( fieldValue != null && String.valueOf( fieldValue ) != 'Other' ) {
totalScoreAchieved += scoreForTheField;
}
}
}
if( totalScorePossible > 0 ) {
acc.Quality_Score__c = ( totalScoreAchieved * 100 ) / totalScorePossible;
}
//accListToUpdate.add( acc );
}
}
// update accListToUpdate;
}
what i am missing in it?
Any suggestions?
What is the debug value of totalScorePossible ?
Cheers!!!
the value of total scorePossible is zero
can you tell me where i am going wrong?
You will not get the value for
String recordTypeDeveloperName = acc.RecordType.developerName
Use RecordTypeId in such case or mapping for the same.
Cheers!!!