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
damo2929damo2929 

Custom Clone routine

Hi all I have a custom object called bids which is used for tendering. I need to be find a way of cloning that allow me to make a deep clone of the object but just for the user to change two mandatory field before it is saved to the database. IE am trying to prevent the user cloning a record that is has a mandatory value of closed being cloned and saved, the user needs to be forced to place it in any other state before it's commited. the second field is the bid closing date which also needs to be forced to a value. any ideas on how I can go about creating the needed clone -> update -> commit routine ?
hisrinuhisrinu

If you are expecting user just to change 2 values then you have to go with visualforce

 

Here you can make all other fields as outputfield and these 2 are as inputfield/inputtext and make it as required.

 

In the controller code, you need to use sobject deepclone method. For more details on these methods you can refer apex guide.

damo2929damo2929

ok, got some of the things working but I am still comming before editing the page.

 

 

problem is if it's cloned this way and the user presses cancel the record has still been commited

 

 

 

    public PageReference cloner() 
    {
        //private Bid__c cBid;
        try 
        {
            Bid__c cBid = bid.clone( false, true);
            cBid.Bid_Type__c = NULL;
            cBID.Submit_Date_Required__c = null;
            insert cBid;
           PageReference bidPage = new PageReference('/apex/BidEditpage?id=' + cBid.Id);
            bidPage.setRedirect(true);
            return bidPage;
        } 
        catch(System.DMLException e) 
        {
            ApexPages.addMessages(e);
            return null;
        }
    }

is there any way of cloning and populating an edit page before the final commit ?

hisrinuhisrinu

You are not suppose to insert the record, you have to make use of parent record values to display in the page using Outputfield and inputfield. As soon as they changed the values and hit on the save then you need to clone the parent record and insert that record.