function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sai dhanasai dhana 

Updating priority when we change the one of the other priority...

HI,

can anyone plz help me out of this urgent requirement..

My requirement is updating the other records priority on priority field when we change any one of priority in the record in inline VF page using triggers(before/after update).

i have a custom custom object  called Deal__C on that  Global_priority__c is picklist fied contains 1-15 integer values. while creating the record user can select priority for the particular record or can update the priority in inline vf page also. when user updates the priority like user is updating his record priority "5" to "10" then 5 becomes 10 and 10 will become 9,9 becomes 8,8 becomes 7,7 becomes 6, 6 becomes 5. means between 5-10 values should be updated like this.(when we cahangin 5-10 , 5 to 10,then from 10 onwards should decrese -1 upto 6 ) we can have deplicate values also. and also if we change 9 th priorty to 4, 9 becomes 4, 4 becomes 5,5 becomes 6,6 becomes 7,7 becomes 8,8 becomes 9 means need to update values between 9-4. here we need to add +1 from 4 upto 8.

here is my sample code. its updating only one value but not other values.

if(trigger.isBefore && trigger.isUpdate){
        
        
        for(Deal__c dl : trigger.new){
            for(integer i = 0 ; i < DList.size();i++){
            if(dl.Global_Priority__c!=null && dl.Global_Priority__c < DList[i].Global_Priority__c){
            
            System.debug('=====fistif======>'+dl.Global_Priority__c);
               DList[i].Global_Priority__c = string.valueof(integer.valueof(dl.Global_Priority__c));
                DList[i].Global_Priority__c = string.valueof(integer.valueof(dl.Global_Priority__c + 1));
                 
             
                
        }
        }
        }   
        } 


Plz share the sample code for my requrement. this is very urget requrement.


Thanks In Advance
sai.
Kevin CrossKevin Cross
If your priorities always are sequential integers, you put items into List in order of priority making the List index equivalent to the priority (or priority minus one if you do not have a priority zero).  If you then use the remove(index) method to grab the item you are moving around, the other items in the list automatically reshuffle.  If you then use add(index, item), you will force the items at and after this index to push back.  This should work but other thought was to create a new List that you fill in three parts.  First with loop through indexes before the one you want to set, add the item where you want it, then loop for the indexes you stopped at before to the end.

I hope that helps. 

Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htm

Respectfully yours, Kevin