+ Start a Discussion
Shavi DabgotraShavi Dabgotra 

Auto-Populate the Opportunity owner as logged in user using VF

I have created a custom Opportunity VF.  I want  the opportunity owner name to be auto- populated as Logged in user and that field should be read only as well. 
User-added imageI am new to this. Can some one help me in this?
Thank you in advance!
AnudeepAnudeep (Salesforce Developers) 
You should be able to do this using a controller

In your extension constructor when you consume the standardcontroller for the object, you will also need to perform a SOQL statement for the parent.  So for the extension, you need to declare an instance of the object
public EntityMaster__c emObject{get;set;}
public EntityRelation__c erObject{get;set;}

//and then in constructor (or alternatively in a method used for page action)
public entitycustomcontroller(ApexPages.StandardController controller)
   this.erObject = (EntityRelation__c)controller;
   this.emObject = [Select Id, Name.......etc from EntityMaster__c Where Id = :erObject.EntityMaster__c];

A similar discussion has happened here (https://trailblazers.salesforce.com/answers?id=90630000000hIfmAAE)

Let me know if this helps