Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a very simple page

<apex:page controller="myController1" >
<c:compo value="hello"></c:compo>

with an empty controller

public with sharing class myController1 {

Component compo is

<apex:component controller="compocontroller">
<apex:attribute name="value" type="string" description="tu" assignTo="{!valueclassvar}"/>

Its controller is

public class compocontroller

public  string valueclassvar{
     return valueclassvar;



When i check the debug log i can see setter gets executed twice.does anyone know why. I know the reason why its executed first(because of assignto attribute in component..but why its getting executed for second time..anyone any clue?

Debug log is

04:11:17.018 (18766000)|EXECUTION_STARTED
04:11:17.018 (18807000)|CODE_UNIT_STARTED|[EXTERNAL]|066i0000004EBS1|VF: /apex/orderofexe
04:11:17.034 (34126000)|CODE_UNIT_STARTED|[EXTERNAL]|01pi0000005trqA|compocontroller <init>
04:11:17.034 (34148000)|SYSTEM_MODE_ENTER|true
04:11:17.034 (34726000)|METHOD_ENTRY|[1]|01pi0000005trqA|compocontroller.compocontroller()
04:11:17.034 (34740000)|METHOD_EXIT|[1]|compocontroller
04:11:17.034 (34815000)|CODE_UNIT_FINISHED|compocontroller <init>
04:11:17.034 (34952000)|CODE_UNIT_STARTED|[EXTERNAL]|compocontroller set(valueclassvar,hello)
04:11:17.034 (34962000)|SYSTEM_MODE_ENTER|true
04:11:17.034 (34972000)|CODE_UNIT_STARTED|[EXTERNAL]|compocontroller set(valueclassvar,hello)
04:11:17.035 (35103000)|SYSTEM_METHOD_ENTRY|[10]|System.debug(ANY)
04:11:17.035 (35145000)|USER_DEBUG|[10]|DEBUG|setmethodvalueclassvar
04:11:17.035 (35154000)|SYSTEM_METHOD_EXIT|[10]|System.debug(ANY)
04:11:17.035 (35168000)|CODE_UNIT_FINISHED|compocontroller set(valueclassvar,hello)
04:11:17.035 (35177000)|CODE_UNIT_FINISHED|compocontroller set(valueclassvar,hello)
04:11:17.038 (38362000)|CODE_UNIT_STARTED|[EXTERNAL]|01pi0000005tsxw|myController1 <init>
04:11:17.038 (38382000)|SYSTEM_MODE_ENTER|true
04:11:17.038 (38425000)|METHOD_ENTRY|[1]|01pi0000005tsxw|myController1.myController1()
04:11:17.038 (38437000)|SYSTEM_MODE_ENTER|false
04:11:17.038 (38444000)|SYSTEM_MODE_EXIT|false
04:11:17.038 (38452000)|METHOD_EXIT|[1]|myController1
04:11:17.038 (38471000)|SYSTEM_MODE_ENTER|false
04:11:17.038 (38483000)|SYSTEM_MODE_EXIT|false
04:11:17.038 (38488000)|SYSTEM_MODE_ENTER|false
04:11:17.038 (38491000)|SYSTEM_MODE_EXIT|false
04:11:17.038 (38501000)|CODE_UNIT_FINISHED|myController1 <init>
04:11:17.062 (62475000)|CODE_UNIT_STARTED|[EXTERNAL]|compocontroller set(valueclassvar,hello)
04:11:17.062 (62498000)|SYSTEM_MODE_ENTER|true
04:11:17.062 (62520000)|CODE_UNIT_STARTED|[EXTERNAL]|compocontroller set(valueclassvar,hello)
04:11:17.062 (62622000)|SYSTEM_METHOD_ENTRY|[10]|System.debug(ANY)
04:11:17.062 (62635000)|USER_DEBUG|[10]|DEBUG|setmethodvalueclassvar
04:11:17.062 (62643000)|SYSTEM_METHOD_EXIT|[10]|System.debug(ANY)
04:11:17.062 (62659000)|CODE_UNIT_FINISHED|compocontroller set(valueclassvar,hello)
04:11:17.062 (62671000)|CODE_UNIT_FINISHED|compocontroller set(valueclassvar,hello)
04:11:17.342 (66472000)|CUMULATIVE_LIMIT_USAGE
share|improve this question
up vote 4 down vote accepted

This is documented behaviour - see:

In the setter section, it states (bold is mine):

It’s a best practice for setter methods to be idempotent, that is, to not have side effects. For example, don’t increment a variable, write a log message, or add a new record to the database. Visualforce doesn’t define the order in which setter methods are called, or how many times they might be called in the course of processing a request. Design your setter methods to produce the same outcome, whether they are called once or multiple times for a single page request.

share|improve this answer
Thanks Bob..Can you please see this query as well,… documentation related to that particular question states otherwise..Not sure whether its me following document wrongly :( – sfdc99999 May 10 '14 at 17:00

Maybe this document will help?

"After custom components are created, all assignTo attributes on those custom components are executed. The assignTo method sets selectedValue on the attribute to the value attribute. The value attribute is set to false, so selectedValue is set to false."

share|improve this answer
as stated in question--i can understand the reason why setter is called for first time(same logic as this document says,assignto reasons)..My specific question is why its executed second time – sfdc99999 May 10 '14 at 16:42
From the logs it looks like 1. On component initialization and 2 on page initialization. Thats how I read it. If I am wrong someone will be along shortly to correct me...Interested to see what the answer is. – Eric May 10 '14 at 18:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.