• **
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

If I see something like the following code:

 

public class wrapper {

    private String string1;

    private Integer int2;

 

   public wrapper {

        this.String1 = 'abc';

        this int2 = 123';

    }

 

   public String getString1() {

        return this.String1;

    }

 

   public Integer getInt2() {

        return this.Int2;

    }

}

 

What do the 'this.'es signify and why would I need them?  Wouldn't the code work the same without them?

 

Thanks in advance.

 

 

 

 

  • December 21, 2011
  • Like
  • 0

If I see something like the following code:

 

public class wrapper {

    private String string1;

    private Integer int2;

 

   public wrapper {

        this.String1 = 'abc';

        this int2 = 123';

    }

 

   public String getString1() {

        return this.String1;

    }

 

   public Integer getInt2() {

        return this.Int2;

    }

}

 

What do the 'this.'es signify and why would I need them?  Wouldn't the code work the same without them?

 

Thanks in advance.

 

 

 

 

  • December 21, 2011
  • Like
  • 0

I read that Apex constructor runs when the VF is being generated, but it doesn't not in my case

 

So i have this Apex code and VF code.

 

public with sharing class ItemsToApproveA {


private final string UserID = UserInfo.getUserId();
private List<ProcessInstance> ProcessInstanceID  {get; set;}
public String getUserID() {return UserID;}

public void ItemsToApproveA(){
  ProcessInstanceID = [SELECT TargetObjectId 
                            FROM ProcessInstance 
                                Where Id IN (SELECT ProcessInstanceId 
                                                FROM ProcessInstanceWorkitem 
                                                    Where ActorId = :UserID)];   


}

public List<ProcessInstance> getProcessInstance() {

    return ProcessInstanceID;
}
                                                 
}

 

<apex:page controller="ItemsToApproveA"> 
   <apex:pageBlock title="Items To Approve">
      <apex:pageBlockTable value="{! ProcessInstance}" var="Items">
         <apex:column value="{! Items.TargetObjectId}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

 

The ProcessInstanceID variable doesn't get assign with any values, unless I move the code below into the getProcessInstance funcation :

  ProcessInstanceID = [SELECT TargetObjectId 
                            FROM ProcessInstance 
                                Where Id IN (SELECT ProcessInstanceId 
                                                FROM ProcessInstanceWorkitem 
                                                    Where ActorId = :UserID)];