• esa
  • 0 Points
  • Member since 2008

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 5
I may have come across another SF bug or at least a documentation hole.  I turned in a case, which I’m told was attached to an existing case.


If you have run this code, the assertion will fail in Winter '09:


global class TestCallByReferenceClass{


public static testMethod void testFunction(){

    Contact con = new Contact();

    System.debug('testFunction- con before: ' + con);


    System.debug('testFunction- con after: ' + con);

    System.assertEquals('TestLast',con.LastName); //Assertion will fail!



public static void Function1(Contact con){

    System.debug('Function1- con before: ' + con);

    con = new Contact();


    System.debug('Function1- con after: ' + con);



To explain what happens in Apex, I need to give a couple of definitions:  "Call by value" means that a function actually gets a copy of a variable to use inside the function.  "Call by reference" means that the variable passed into a function is the variable itself.  Call by reference should make changes to a parameter variable inside the function be in the parameter variable after the function call ends because the variable outside and inside the called function are one and the same.

Apex is supposed to pass all objects by value, but there is a bit of a twist.

It turns out that the Contact "con" parameter in the code above is created as a reference variable to the real object and that reference variable is passed using call by value into the function.


The affect of this is that the "con" reference parameter that the function starts executing with is reassigned to hold a reference to the new object and forgets about the original object it was referencing.  When the function returns, the outer "con" object is still there untouched, but the "con" object with its LastName change went away with the copy of the reference variable that had existence only inside the function.

If you remark out the "con = new Contact();" line in Function1, the assertion does not fail because there is no reference variable reassignment.  The outer Contact "con" hooks to the same "con" inside the function so the changed LastName value is available when the function finishes.


This is the way Java behaves and I understand SF is programmed in Java.


SalesForce needs to document clearly if Apex behaves properly in this case, or fix Apex so that the function parameters to objects pass newly created objects out to be available when the function exits.

Message Edited by Jim Cripe on 01-15-2009 09:19 PM
How do you craft a URL to default field values on a new record that I want to create from a sidebar link?
For example, if I create a new child record from a parent object, the url I'm directed to is something like this:
Where CF00N50000001xQY6 seems to be some internal value for the parent record association and when the URL renders the parent record value is populated in the new edit record form.
So, how do I find out the id values for other fields I want to pass to this URL? For example, here is what I'm trying to do, but it does not work:
Any ideas?
Also, how would I do this URL so that another page layout is displayed instead of the default page layout for a profile? How would I craft the URL to dictate which page layout is displayed and how do I find the ID for that page layout?
For suppose path of the file I am uplaoding is the below one:
C:\Documents and Settings\rajnoot\Desktop\login.txt
Here Name of the file is login.txt,So how to retrieve this file name,when I am uploading this file.
I used below Code:But it is not working::::
Page Editor Code:::
<apex:page StandardController="Document" extensions="documentExt">
    <apex:form >
      <apex:pageBlock >
            <apex:inputFile value="{!document.body}" filename="{!document.name}"/>
            <apex:commandButton value="save" action="{!save1}"/>
            <apex:param name="q" value="{!document.name}"/> <!Tried using this -->
Controller Code:::
public class documentExt {
String path;
ApexPages.StandardController controller;       
public documentExt(ApexPages.StandardController controller)
               Document d = (Document) controller.getRecord();
               d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
// ** Overriding the save method **  
public PageReference save1()
System.debug('Uplaoded File Name is:::'+ path); /*showing path Value as NULL*/
return page.docsample;
Please Suggest me,How to get file name in path variable
I have created a work flow rule on opportunities that sends an email notification everytime a opportunity has been created or edited. However, is there a way to have the flow rule work send an email notificiation only when a new opportunity has been created or when the stage has been changed? 
Sometimes the stage can go back to previous stage so the option "When a record is created, or when a record is edited and did not previously meet the rule criteria" would not work for me. I don't want an email sent everytime an edit has been done.