0

I'm in a need to create a custom button that will be placed on the standard page layout and that button will call to clone the record which the user is on and I could have used the standard clone functionality but my requirement is that the user does not want all the fields to be clone so it will be selected fields that needs to be cloned so when the user click on the button.

What are the options I have in this particular scenario ?

One thing I have think of is creating a Detail page button and write the javascript code and that JS will call the APEX controller something like this:

{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}

var myId = "{!Employee__c.Id}";

//this apex class method will clone the record
sforce.apex.execute('apexControllerClass','CloneME',{sObjectId: myId });

apexControllerClass:

webService static void CloneME(Id sObjectId) 
{
   //clone the record?
}

Is that even possible doing this on standard page layout?

  • Do you want the user to click Clone and be able to enter new values? or just clone and present them with a new detail page (a clone) with selected fields removed? If the latter, a VF page+controller or Flow will work – cropredy Mar 23 '17 at 0:43
  • How do you want selected fields to be cloned? Where you will select the fields? – Santanu Boral Mar 23 '17 at 4:55
0

How about using Flow and custom button? I mean without code it is possible.

P.S. :- Currently JavaScript is not supported in Lightning Experience.

  • 1
    can you elaborate little more with an example what you mean by flow and custom button? – Nick Kahn Mar 22 '17 at 23:07
  • I mean to say create a button (Detail page button) and instead of calling JavaScript call Visual Workflow. There you can manage your own custom logic, i mean to say filter fields and clone child records too. Here is one example for you automationchampion.com/2014/04/23/… – J Doe Mar 22 '17 at 23:10
  • I'm not sure if this works in my situation because I'm looking to make a more generic approach then creating for each object and i have dozens of object. – Nick Kahn Mar 22 '17 at 23:29
0

You can use the same what you have written, just use the below code in your "CloneME" function : -

cloneOpp = eachOpp.clone(false);

where cloneOpp is the newly created record instance and eachOpp is the existing record instance.

if you want to clone all the fields then you need to use eachOpp.clone(true).

After using the parameter as "False" use can manipulate the field value for newly created record like below: -

eachOpp.Field1__c = some value;

eachOpp.Field12__c = some value;

then you can insert the new record.Hope this will serve your purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.