Cubic Compass Software
The following Dialogue Script is handy for taking a snapshot of any Salesforce record and generating a restore script.

An example use case might be testing a portal application experience for a first time Contact visitor. Upon logging in several Contact fields may get updated, requiring a manual restore of certain fields to re-test.

The codegen script below allows for one-click restore of the test Contact record to quickly resume testing.

<h1>Generate Salesforce Record Baseline Script</h1>
Object Type: <dlog:TextBox id="ObjectType" />
RecordId: <dlog:TextBox id="RecordID" />
<dlog:Button id="SubmitButton" Text="Generate Baseline Script" /><br/>
<dlog:Label id="Output" />
<%
from CubicCompass.Portal.Webparts.Salesforce.sForce import *

def CodeGen():
objectDescription = SalesforceSettings.Instance.SForceService.describeSObject(ObjectType.Text)
query = "select "
for field in objectDescription.fields:
query += field.name + ", "

query = query.TrimEnd(", ".ToCharArray())
query += " from " + ObjectType.Text

if RecordID.Text.Length > 0:
query += " where Id='" + RecordID.Text + "'"

result = SalesforceSettings.Instance.SForceService.query(query)
if result.size == 0:
Output.Text = "record not found"
return

sObject = SalesforceObject(result.records[0])

indent = "    "
code = "def Reset" + ObjectType.Text + "Defaults():<br/>"
code += indent + "sforce = SalesforceWebService()<br/>"
code += indent + "sforce.SalesforceRecordID = \"" + RecordID.Text + "\"<br/>"
for field in objectDescription.fields:
if field.updateable == False:
continue
code += indent + "sforce.AddField(\"" + field.name + "\", \"" + sObject.GetProperty(field.name) + "\")<br/>"

code += indent + "sforce.UpdateObject(\"" + ObjectType.Text + "\")<br/>"
Output.Text = code

if Page.IsPostBack:
if ObjectType.Text.Length == 0 or RecordID.Text.Length == 0:
Output.Text = "missing values"
else:
CodeGen()

else:
ObjectType.Text = "Account"
RecordID.Text = "testRecordId"
%>
Posted: Monday, October 19, 2009 4:57:39 PM (GMT Standard Time, UTC+00:00)  #   
Comments [0]  | 
Comments are closed.