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
ASMASM 

Move data from one custom object to another using S-Control or VF Page

How can I move data using VF or S-Control from one custom object to another custom object ?  I want to set up a condition or a button which when clicked would copy the field values from one custom object A into custom object B. I want a automated process which pre-populate fields which need not be re-entered.
 
Thanks,
Anusha
  
soofsoof

Hey Anusha,

Here's some sample S-Control code:

Code:
var srcObj = sforce.connection.retrieve(
    "Id, Name, Custom_Field1__c, Custom_Field2__c, Custom_Field3__c", 
    "Source_Custom_Object__c", ["ID_OF_THE_SOURCE_CUSTOM_OBJECT"]);

var trgtObj = new sforce.SObject("Target_Custom_Object__c");
trgtObj.set("Name", srcObj[0].get("Name"));
trgtObj.set("Custom_Field1__c", srcObj[0].get("Custom_Field1__c"));
trgtObj.set("Custom_Field2__c", srcObj[0].get("Custom_Field2__c"));
trgtObj.set("Custom_Field3__c", srcObj[0].get("Custom_Field3__c"));

var saveResult = sforce.connection.create([trgtObj]);
alert(saveResult[0].getBoolean("success") — "Operation Successful" : "Operation Failed");


 

I hope this hepls!

ASMASM
Thanks for replying.
NordbergNordberg
Hi Soof,

I am trying to do the same thing execpt I want to take data from the Case object and copy it over to a custom object.  Here is my code that I placed as a S-control trigged by a detail page button on the case.  What am I missing or am I missing the entire boat?


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Copy Data From Convereted Lead</title> 
<HEAD>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script type="text/javascript"> 

var srcObj = sforce.connection.retrieve(
    "Id, Employee_First_Name__c, Employee_Last_Name__c, Address_line_1__c", 
    "Case", ["Case"]);

var trgtObj = new sforce.SObject("Employee__c");
trgtObj.set("Employee_Last_Name__c", srcObj[0].get("Employee_Last_Name__c"));
trgtObj.set("First_Name__c", srcObj[0].get("Employee_First_Name__c"));
trgtObj.set("Street_Address__c", srcObj[0].get("Address_line_1__c"));


var saveResult = sforce.connection.create([trgtObj]);
alert(saveResult[0].getBoolean("success") — "Operation Successful" : "Operation Failed");

</script>
</HEAD>
<body>
</body>
</html>

 Thank you for any help,

JD

StatBoyAStatBoyA
Nordberg,

I'm far from an expert, but it seems to me you're CODE looks like you're using "production" version of the Ajax toolkit

For example,:

   sforce.connection
   sforce.SObject

However, in your header you reference the "beta3.3" toolkit. Under the beta toolkit, the approach to requesting similar function would be quite different.

If you want one of the non-beta toolkits to be used, I think you need instead a header reference to something like "/soap/Ajax/13.0/connection.js"