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
AustralianBobAustralianBob 

REAL VF beginner, wont save a Field

Hi,

 

Probably missed something, but I HAVE looked. Just starting to scratch around at VF

 

We have a Custom Object. We have a button to clone a copy of a template in this Object, all good.

 

Want to add to the Clone VF page the ability to set a user (Project Officer)

 

Reading around, this code looks promising

 

<apex:inputField value="{!Milestone1_Project__c.Project_Officer__c}"
    required="true"/> 

 

it even works! Brings up a lookup and you can pick, in fact you can't press Save unless you do!

:)

 

Then when you save, it hasn't recorded what you picked :(

 

What have I missed?

jiah.choudharyjiah.choudhary

Hi @AustralianBob,

 

Could you please share the Save functionality that you are doing at controller end?

AustralianBobAustralianBob

Hi Jiah,

 

I'm new to all this so sing out if I'm telling you the wrong info. The Page references the standard controller for that custom object and an extension for cloning, I think the save code is this... let me know if this is the wrong snippet or I have not included enough!

 

    public PageReference createClone(){      
        Savepoint preSave = Database.setSavepoint(); //set savepoint so we can rollback the whole save if there are errors
        PageReference pageReference = null;
        try{
            
          if(isProjOwnerActive == false){
                if(dummyProj.OwnerId == null){
                   ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,system.label.Milestone1_InactiveUsersError);
                   ApexPages.addMessage(myMsg);
                   isInactiveUserToBeReplaced = true;
                   return pageReference;
                }if(dummyProj.OwnerId != null){
                    rec.ownerId = dummyProj.OwnerId;                 
                }
            }            

 

 

Thanks for your help :)

 

 

jiah.choudharyjiah.choudhary

@AustralianBob,

 

Send me the code where you have done some DML operation to save the record.

AustralianBobAustralianBob

Thanks Jiah,

 

DML Operations means commands like Insert, Upsert etc? From the Controller?

 

So the issue is that I am asking for an capturing the Field on the VF Page, but the controller needs to refer to it and do something with the information?

jiah.choudharyjiah.choudhary
@AustralianBob,

It would be better if you explain me your requirement bit more.
AustralianBobAustralianBob

Thanks for your patience Jiah.

Essentially we are using the Milestones Package, everything works quite well and we're using a button to Clone a "Template" Project whenever we need to spin up a new one.

 

What we'd like to be able to do is, as part of that Clone step, set the Project Officer.

 

This is a Lookup to User Field and a few workflows will work a little more fluidly if we can have this set from the point of creation.

 

I have succeeded in added the Project Officer Field to a modification of the Clone Project VF page

It APPEARS to work, but when you save the record the Project Officer Field is blank...