You need to sign in to do that
Don't have an account?
I want to test that x fields have a value and calculate a score.
Im trying to convert the following javascript to java code but have a hard time since im new to the java syntax.
Can someone please help me to get started.
JAVASCRIPT:
varFieldScore = 0
varFieldCounter = 0
funAddScore("{!Opportunity.Name}")
funAddScore("{!Opportunity.Type}")
funAddScore("{!Opportunity.NextStep}")
// FUNCTION
function funAddScore(iField){
varFieldCounter = varFieldCounter +1
if( iField.length > 1){
varFieldScore = varFieldScore +1
}
}
varPercent = varFieldScore / varFieldCounter * 100
varPercent = Math.round(varPercent)
alert("varFieldScore=" +varFieldScore +" varFieldCounter= " +varFieldCounter +" varPercent =" +varPercent )
I havent come far with the java version. The output should be in a field called "field score" on the opportunity object.
JAVA VERSION:
trigger trgMnTest on Opportunity(before update) {
// SET VARIABLE
Private integer intCountScore = 0;
Private integer intFieldCount = 0;
private Opportunity[] oppObj = Trigger.new;
// TEST FIELD AMOUNT
intFieldCount = intFieldCount +1;
if(oppObj[0].Amount > 0){
intCountScore = intCountScore +10;
}
oppObj[0].NextStep = 'Hello World ' +intCountScore;
}
PS THIS FORUM THROWS AN ERROR WHEN POSTING USING IE8. PLEASE FIX DS
Idea: http://sites.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=087300000007Mj0AAE
Without any knowledge in Java i have succeded doing the following... and it works...
Just add the field names and a message to calculate more fields. =)
trigger trgMnTest on Opportunity(before update){
// SET VARIABLES
Private double intCountScore = 0;
Private double intFieldCount = 0;
// CREATE ARRAY AND NAME IT oppObj
private Opportunity[] oppObj = Trigger.new;
// EMPTY TO DO MESSAGE
oppObj[0].Field_score_action__c = '';
// TEST FIELD AMOUNT
addCountIfValue(oppObj[0].Primary_Quote_Number__c, 'Primary quote number is missing');
// TEST FIELD Description
addCountIfValue(oppObj[0].Description, 'Description text is missing');
// ADD SCORE IF VALUE EXIST
public void addCountIfValue(string iFieldValue, string iToDoMessage){
// REMEMBER AMOUNT OF FIELDS
intFieldCount = intFieldCount +1;
// ADD TO SCORE IF VALUE EXIST
if(iFieldValue != null){
intCountScore = intCountScore +1;
}else{
// SEND TO DO MESSAGE IF VALUE DOES NOT EXIST
oppObj[0].Field_score_action__c = '' +iToDoMessage;
}
}
// OUTPUT
intCountScore = (intCountScore / intFieldCount *100);
oppObj[0].Field_score__c = intCountScore;
//oppObj[0].NextStep = '' +intCountScore +' ' +intCountScore +' ' +intFieldCount +' ' +(intCountScore / intFieldCount)*100;
}