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
ALEJO CARPENZANOALEJO CARPENZANO 

set custom field values from visualforce

Hi!, in visualforce i got an UL with Account records. Now i must to set the value of a custom field of that record with a new value.¿How can i pass the list of records to my controller? Thanks!
Magesh Mani YadavMagesh Mani Yadav
Hi Alejo,
Can you provide your code.
ALEJO CARPENZANOALEJO CARPENZANO
<apex:page standardController="Account" extensions="getAccController">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  	<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
  	<script>
  	$( function() { 
    $( "#sortable1, #sortable2 ,#sortable3" ).sortable({
      connectWith: ".connectedSortable",
      update : function(event,ui){
          //aqui deberia llamar una funcion jquery que invoque métodos en el controlador para updatear los registros en la base de datos
          /*function upd(){
        apexupd1(document.getElementById("#sortable1"));//cada uno de los métodos recibe la lista de cuentas luego de un drag
        apexupd2(document.getElementById("#sortable2"));
        apexupd3(document.getElementById("#sortable3"));
        }*/
      }
    	}).disableSelection();
  	} );
  	</script>
    <script>
    $( function() {
       /* $("#btn").click(function(){  éstos métodos se ejecutan cuando se hace clic en el boton save
                apexupd1(document.getElementById("#sortable1"));//se ejecutan tres métodos que recorren las nuevas listas de cuentas
        	apexupd2(document.getElementById("#sortable2"));//para cambiar su campo NIVEL__c por el valor correspondiente
        	apexupd3(document.getElementById("#sortable3"));
            });*/
        }
    </script>
    <apex:pageMessages />
    	<apex:pageBlock id="cuentas">
        	<apex:pageBlockSection >
    	<apex:form >
                    <!--<apex:actionFunction name="apexupd1" action="{!actioncontroller1}"/>--><!-- éstos actionfunction se utilizan para-->
                    <!--<apex:actionFunction name="apexupd2" action="{!actioncontroller2}"/>--><!-- llamar una función del controlador -->
                    <!--<apex:actionFunction name="apexupd3" action="{!actioncontroller3}"/>--><!-- mediante jquery -->
                    <apex:pageBlock>
                    	<apex:pageBlockButtons>
                        	<apex:commandButton id="btn" value="Save changes" onclick="upd();"/>
                        </apex:pageBlockButtons>
                    </apex:pageBlock>
                	<h1>Cuentas de nivel 1: </h1>
    	<ul id="sortable1" class="connectedSortable">
        	<apex:repeat var="account" value="{! accountslv1}">
        	<li>{!account.name} - {!account.NIVEL__c}</li>
        	</apex:repeat>
        	</ul>
        	<h1>Cuentas de nivel 2: </h1>
    	<ul id="sortable2" class="connectedSortable">
    	    	    <apex:repeat var="account" value="{! accountslv2}">
    	    	    	<li>{!account.name} - {!account.NIVEL__c}</li>
    	    	    </apex:repeat>
    	    	</ul>
    	    	<h1>Cuentas de nivel 3: </h1>
    	<ul id="sortable3" class="connectedSortable">
    	    	<apex:repeat var="account" value="{! accountslv3}">
    	    	<li>{!account.name} - {!account.NIVEL__c}</li>
    	    	</apex:repeat>
    	    </ul>
                </apex:form>
    	</apex:pageBlockSection>
    	</apex:pageBlock>	
</apex:page>
 
public class getAccController {
    //inicializa las listas para cada nivel como get set.
    public List<Account> accounts1 {get;set;}
    public List<Account> accounts2 {get;set;}
    public List<Account> accounts3 {get;set;}
    
    public Account aux {get;set;}
    ApexPages.StandardController scontroller;
    
    public getAccController(ApexPages.StandardController controller){
        aux = (Account)controller.getRecord();
        scontroller = controller;
    }
    
    //cada método devuelve una lista de cuentas según el nivel especificado en : in ('nivel')
    public List<Account> getAccountslv1 (){
        accounts1 = [SELECT name, NIVEL__c from Account WHERE NIVEL__c IN ('nivel1')];
        return accounts1;
    }
    
    public List<Account> getAccountslv2 (){
        accounts2 = [SELECT name, NIVEL__c from Account WHERE NIVEL__c IN ('nivel2')];
        return accounts2;
    }
    
    public List<Account> getAccountslv3 (){
        accounts3 = [SELECT name, NIVEL__c from Account WHERE NIVEL__c IN ('nivel3')];
        return accounts3;
    }
    
    /*public void actioncontroller1(List<Account> ulist){ las funciones reciben la lista de accounts de la vfpage
        for(Account a : ulist){	  se las recorre con un foreach y se actualiza su campo nivel
            a.NIVEL__c='nivel1';
            upsert a;
        }
    }*/
    /*public void actioncontroller2(List<Account> ulist){
        for(Account a : ulist){
            a.NIVEL__c='nivel2';
            upsert a;
        }
    }*/
    /*public void actioncontroller3(List<Account> ulist){
        for(Account a : ulist){
            a.NIVEL__c='nivel3';
            upsert a;
        }
    }*/
}

thanks for reply! must to solve this please help me! =P
Magesh Mani YadavMagesh Mani Yadav
Hi Alejo,

Do you want this field NIVEL__c to be updated?
May i know why did you hardcod nivel1,nivel2 and nivel3?  because if new value gets updated then you wont be able to fetch records for getAccountslv1,getAccountslv2,getAccountslv3
ALEJO CARPENZANOALEJO CARPENZANO
Hi! Basically i must create a New custom field on account record (nivel__c), this field should be able to take three different values (nivel1,2,3). Then, in VF, must to list the records based on the value of this field. (an UL with the nivel1 accounts, an ul with nivel2 accounts, an ul with nivel3 accounts). This three list must be able to drag and drop record from one list to another and finally,save changes. (Update the new nivel__c value of records based on wich list the record was dropped.) . I'm newbie, sorry! Maybe I was doing something bad. Thanks
José Puig BelloliJosé Puig Belloli
Can you do this?