3

I am testing out cloning an account, but I would like the system to not clone some to the objects/fields. For example, I would like the clone button to clone the Address, phone and other info but not the Name. I would also like the clone to not clone the opportunities either, as currently the opportunities are auto populated for each location when the account is created. How can I do this? I have followed these steps as outline in the article: https://success.salesforce.com/answers?id=90630000000gr6CAAQ.

Help would be greatly appreciated.

1

For what you would like, there is simple way I can see you doing this. On your button you can set your values via the URL and salesforce will map them to their correct field as long as you match the input field id.

Note: Depending on the amount of work this will probably be the simplest way of achieving this goal

Example Button (Clearing out values from account to clone from):

Behavior: Execute Javascript

Content Source: OnClick Javascript

var url = '{!Account.Id}/e?clone=1&Name=&Phone=';

window.location.href = url; 

Note: Custom fields will have an Id while standard fields do not when referencing them as shown via the example button on top.

The other way you can approach this is populating the values head of time of what you want to copy.

Example Button (Setting specific values from account you want to clone from):

Behavior: Execute Javascript

Content Source: OnClick Javascript

var url = '001/e?Phone={!Account.Phone}&Type={!Account.Type}';

window.location.href = url; 

Note: Custom fields will have an Id while standard fields do not when referencing them as shown via the example button on top.

0

Opportunity is a different object than Account. When you clone an Account, you'll only be cloning that particular sObject unless you decide to specifically clone additional related objects as well. It also depends on whether you decide to clone related objects by doing a choosing whether or not to do a deep clone.

There's a "clone" and there's also a "deep clone". The latter is a full copy that's also held in memory with the original. You can also include the read-only time stamps in clone as well as the Id's. See below for the options when doing a clone and refer to the sObject class section of the Force.com Apex Code Developer's Guide for additional info.

Here are some important parameters:

opt_preserve_id

Type: Boolean (Optional)

Determines whether the ID of the original object is preserved or cleared in the duplicate. If set to true, the ID is copied to the duplicate. The default is false, that is, the ID is cleared.

opt_IsDeepClone

Type: Boolean (Optional)

Determines whether the method creates a full copy of the sObject field, or just a reference: If set to true, the method creates a full copy of the sObject. All fields on the sObject are duplicated in memory, including relationship fields. Consequently, if you make changes to a field on the cloned sObject, the original sObject is not affected. If set to false, the method performs a shallow copy of the sObject fields. All copied relationship fields reference the original sObjects. Consequently, if you make changes to a relationship field on the cloned sObject, the corresponding field on the original sObject is also affected, and vice-versa. The default is false.

opt_preserve_readonly_timestamps

Type: Boolean (Optional)

Determines whether the read-only timestamp fields are preserved or cleared in the duplicate. If set to true, the read-only fields CreatedById, CreatedDate, LastModifiedById, and LastModifiedDate are copied to the duplicate. The default is false, that is, the values are cleared.

opt_preserve_autonumber

Type: Boolean (Optional)

Determines whether auto number fields of the original object are preserved or cleared in the duplicate. If set to true, auto number fields are copied to the cloned object. The default is false, that is, auto number fields are cleared. Return Value Type: sObject (of same type)

0

If you need more functionality, you may want to look at iClone app on AppExchange. https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B39tWEAR

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.