1

I have made a Visualforce page that I am using to create Leads from data held in a custom object, new data is added to this daily and distributed between 2-4 Users. To choose these users I have 4 dropdown menus on my page:

Dropdowns

I have used the following code (trimmed down) within my for loop to create the Leads:

String sRep1 = Apexpages.currentPage().getParameters().get('sRep1'); 
String sRep2 = Apexpages.currentPage().getParameters().get('sRep2');
String sRep3 = Apexpages.currentPage().getParameters().get('sRep3'); 
String sRep4 = Apexpages.currentPage().getParameters().get('sRep4');
String usedId;

            //For 4 sReps
            IF((sRep3 != '') && (sRep4 != '')){
                IF(usedId == null){
                    usedId  =   sRep1;      
                }
                ELSE IF(usedId == sRep1){
                    usedId  =   sRep2;      
                }
                ELSE IF(usedId == sRep2){
                    usedId  =   sRep3;      
                }
                ELSE IF(usedId == sRep3){
                    usedId  =   sRep4;      
                }
                ELSE IF(usedId == sRep4){
                    usedId  =   sRep1;
                }
            }

            //For 3 sReps
            IF((sRep3 != '') && (sRep4 == '')){  
                IF(usedId == null){
                    usedId  =   sRep1;
                }
                ELSE IF(usedId == sRep1){
                    usedId  =   sRep2;
                }
                ELSE IF(usedId == sRep2){
                    usedId  =   sRep3;
                }
                ELSE IF(usedId == sRep3){
                    usedId  =   sRep1;
                }
            }

            //For 2 Reps
            IF((sRep3 == '') && (sRep4 == '')){
                IF(usedId == null){
                    usedId  =   sRep1;
                }
                ELSE IF(usedId == sRep1){
                    usedId  =   sRep2;
                }
                ELSE IF(usedId == sRep2){
                    usedId  =   sRep1;
                }
            }

This worked fine for my initial tests but there are some cases where the distribution will be uneven, for example:

User1: 50%

User2: 25%

User3: 25%

Ideally in this particular case I would like to be able to select User1 in two of the dropdowns and User2/User3 in the other two but my current code does not handle this. I feel like there is a simple solution I am missing but just can't figure it out. Hopefully this make sense, I would really appreciate a bit of help with this.

1
  • I just get the feeling that this is not good design, this page has to be redesigned to account for 1. the issue you posted, 2. new sales rep added in future. 3. implement code to be dynamic rather than static. Can you tell me what do we have in the drop downs? is it list of records of this custom object. Aug 18, 2015 at 5:37

2 Answers 2

1

enter image description here

Create another dropdown for percentage and on controller side do calculation based on total leads. Using list you can do the assignment for every user. The third column is optional if you would like to extend it further with the option of entering number of leads as well.

Plus using javascript you can show the real time changes when percentage selected how many leads will be processed in number of leads.

0

I didn't have a great deal of time to work on this but I finally thought of a simple solution to my problem by using a few incrementing counters to decide which dropdown to use instead of comparing the values of each dropdown. Its probably not the most elegant solution but it works!

for(Data_Vault__c d : leadDataDupe.values()){

            Counter4 += 1;
            Counter3 += 1;
            Counter2 += 1;

            IF(Counter4 == 5){
                Counter4 = 1;
            }

            IF(Counter3 == 4){
                Counter3 = 1;
            }

            IF(Counter2 == 3){
                Counter2 = 1;
            }

            //If statements to share records
            //For 4 sReps
            IF((sRep3Dupe != '') && (sRep4Dupe != '')){
                    IF(Counter4 == 1){
                        usedIdDupe  =   sRep1Dupe;
                    }
                    ELSE IF(Counter4 == 2){
                        usedIdDupe  =   sRep2Dupe;
                    }
                    ELSE IF(Counter4 == 3){
                        usedIdDupe  =   sRep3Dupe;
                    }
                    ELSE IF(Counter4 == 4){
                        usedIdDupe  =   sRep4Dupe;
                    }
            }

            //For 3 sReps
            IF((sRep3Dupe != '') && (sRep4Dupe == '')){  
                IF(Counter3 == 1){
                    usedIdDupe  =   sRep1Dupe;
                }
                ELSE IF(Counter3 == 2){
                    usedIdDupe  =   sRep2Dupe;
                }
                ELSE IF(Counter3 == 3){
                    usedIdDupe  =   sRep3Dupe;
                }
            }

            //For 2 Reps
            IF((sRep3Dupe == '') && (sRep4Dupe == '')){
                IF(Counter2 == 1){
                    usedIdDupe  =   sRep1Dupe;
                }
                ELSE IF(Counter2 == 2){
                    usedIdDupe  =   sRep2Dupe;
                }
            }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .