Wednesday, March 4, 2009

Rotation Angle Issue

When transitioning an angle with value > 180 or < 0, using this function to fix the problem.
function properRotation(target_rotation,my_rotation,smooth) {
var rot =target_rotation-my_rotation;
while (rot<0) {
rot += 360;
}
while (rot>180) {
rot -= 360;
}
my_rotation += rot/smooth;
return my_rotation;
}


Thanks the thread from http://www.mail-archive.com/away3d-dev@googlegroups.com/msg02572.html

Case 2:

Simple as using

var diffAngle:Number = Math.atan2(Math.sin(angleTo - currentAngle)
                Math.cos(angleTo - currentAngle));


Example:

var currentAngle: Number = 0;
var angleTo: Number = 120 * Math.PI / 180;
var diffAngle:Number = Math.atan2(Math.sin(angleTo - currentAngle)
            Math.cos(angleTo - currentAngle));

diffAngle = Math.round(diffAngle*180 / Math.PI);

trace("diffAngle: " + diffAngle);

Friday, February 27, 2009

Water Effect AS2

import flash.display.BitmapData;
import flash.filters.ConvolutionFilter;
import flash.filters.DisplacementMapFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import mx.utils.Delegate;
/**
* ...
@author binhdocco
*/
class WaterEffect extends Object {
private var mc: MovieClip;
private var IMAGE_WIDTH: Number;
private var IMAGE_HEIGHT: Number;
private var IMAGE_ID: String;
private var damper: BitmapData;
private var result: BitmapData;
private var result2: BitmapData;
private var source: BitmapData;
private var buffer: BitmapData;
private var output: BitmapData;
private var surface: BitmapData;
private var bounds: Rectangle;
private var origin: Point;
private var wave: ConvolutionFilter;
private var damp: ColorTransform;
private var water: DisplacementMapFilter;
private var matrix: Matrix;
private var matrix2: Matrix;
private var mouseUp: Boolean = true;

public function WaterEffect(mc: MovieClip, imageId: String) {
this.mc = mc;
this.IMAGE_ID = imageId;
surface= BitmapData.loadBitmap(this.IMAGE_ID);
var tempMC: MovieClip = mc.createEmptyMovieClip("dummy_mc", mc.getNextHighestDepth());
tempMC.attachBitmap(surface, 1);
this.IMAGE_WIDTH = tempMC._width;
this.IMAGE_HEIGHT = tempMC._height;
tempMC.removeMovieClip();
damper= new BitmapData(IMAGE_WIDTH/2, IMAGE_HEIGHT/2false128);
result= new BitmapData(IMAGE_WIDTH/2, IMAGE_HEIGHT/2false128);
result2= new BitmapData(IMAGE_WIDTH, IMAGE_HEIGHT, false128);
source= new BitmapData(IMAGE_WIDTH/2, IMAGE_HEIGHT/2false128);
buffer= new BitmapData(IMAGE_WIDTH/2, IMAGE_HEIGHT/2false128);
output= new BitmapData(IMAGE_WIDTH, IMAGE_HEIGHT, true128);

bounds= new Rectangle(00, IMAGE_WIDTH/2, IMAGE_HEIGHT/2);
origin= new Point();
matrix= new Matrix();
matrix2= new Matrix();
matrix2.a = matrix2.d = 2;
wave= new ConvolutionFilter(33[111111111]90);
damp= new ColorTransform(009.960937E-00110020);
water= new DisplacementMapFilter(result2, origin, 443232"ignore");

this.mc.attachBitmap(output, 0);

var thisObj = this;
mc.onEnterFrame = Delegate.create(this, enterFrame);
mc.onMouseUp = function() {
thisObj.mouseUp = true;
}
mc.onMouseDown = function() {
thisObj.mouseUp = false;
}
}

private function enterFrame():Void {
if (mouseUp)
{
var xMouse = this.mc._xmouse / 2;
var yMouse = this.mc._ymouse / 2;
source.setPixel(xMouse + 1, yMouse, 16777215);
source.setPixel(xMouse - 1, yMouse, 16777215);
source.setPixel(xMouse, yMouse + 116777215);
source.setPixel(xMouse, yMouse - 116777215);
source.setPixel(xMouse, yMouse, 16777215);
// end if
result.applyFilter(source, bounds, origin, wave);
result.draw(result, matrix, null"add");
result.draw(buffer, matrix, null"difference");
result.draw(result, matrix, damp);
result2.draw(result, matrix2, nullnullnulltrue);
output.applyFilter(surface, new Rectangle(00, IMAGE_WIDTH, IMAGE_HEIGHT), origin, water);

buffer = source;
source = result.clone();
}

ImageGallery 1

package blueroad.todo.imagegallery1 { //blueroad.todo.imagegallery1.ImageGallery1
import blueroad.base.PaperBase;
import caurina.transitions.Tweener;
import com.pixelfumes.reflect.ReflectBitmap;
import flash.display.Bitmap;
import flash.display.MovieClip;
import org.papervision3d.core.utils.InteractiveSceneManager;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.objects.primitives.Plane;

/**
* ...
* @author binhdocco
*/
public class ImageGallery1 extends PaperBase {

private var num:uint = 0;
private var totalThumbs:uint = 0;
private var planes: Array;
private var currentIndex: int = 0;
public var isShowingLargeImage: Boolean = false;
//PLANE STATUS
public const STATUS_HOVER: String = "STATUS_HOVER";
public const STATUS_NORMAL: String = "STATUS_NORMAL";
public const STATUS_ACTIVE: String = "STATUS_ACTIVE";
public const STATUS_TWEENING: String = "STATUS_TWEENING";
public function ImageGallery1() {
this.init();
}

override protected function init2d():void {
super.init2d();
totalThumbs = Global_ImageGallery1.resourceManager.total;
planes = new Array();
}

override protected function init3d():void {
//super.init3d();
current_camera.zoom = 10;
current_camera.z = 1000;
current_camera.x = 8000;

createThumb();
}

private function createThumb():void {
num = 0;
for (var i:int = 0; i < totalThumbs; i++) {
var thumbXML: XML = Global_ImageGallery1.resourceManager.imageXMLList[i];
var thumb: String = Global_ImageGallery1.resourceManager.sourceImagePath + "/" + thumbXML.@image_icon;
var image: String = Global_ImageGallery1.resourceManager.sourceImagePath + "/" + thumbXML.@image;

var mat: BitmapFileMaterial = new BitmapFileMaterial(thumb as String);
mat.updateBitmap();
//mat.doubleSided = true;
mat.smooth = true;
mat.interactive = true;
mat.extra = {id: i, image: image, index: i };
mat.addEventListener(FileLoadEvent.LOAD_COMPLETE, createPlane);
}
}

private function onOutPlane(e:InteractiveScene3DEvent):void {
if (isShowingLargeImage) return;
current_viewport.buttonMode = false;
var plane: Plane = e.displayObject3D as Plane;
if (plane.extra.status == STATUS_HOVER) {
if (!Tweener.isTweening(current_camera)) {
var x = plane.extra.pos.x;
var z = plane.extra.pos.z;
var refPlane: Plane = current_scene.getChildByName("refPlane" + plane.extra.id) as Plane;
Tweener.addTween(plane, { x:x, z:z, time:1, transition:"easeOutCubic" } );
Tweener.addTween(refPlane, { x:x, z:z, time:1, transition:"easeOutCubic" } );
}
plane.extra.status = STATUS_NORMAL;
}

}

private function onOverPlane(e:InteractiveScene3DEvent):void {
if (isShowingLargeImage) return;
current_viewport.buttonMode = true;
var plane: Plane = e.displayObject3D as Plane;
if (plane.extra.status == STATUS_NORMAL) {
if (!Tweener.isTweening(current_camera)) {
var x = plane.extra.pos.x + 200 * Math.sin(55 * (Math.PI / 180));
var z = plane.extra.pos.z - 200 * Math.cos(55 * (Math.PI / 180));

var refPlane: Plane = current_scene.getChildByName("refPlane" + plane.extra.id) as Plane;

Tweener.addTween(plane, { x:x, z:z, time:1, transition:"easeOutCubic" } );
Tweener.addTween(refPlane, { x:x, z:z, time:1, transition:"easeOutCubic" } );
}
plane.extra.status = STATUS_HOVER;
}
}

private function onPressPlane(e:InteractiveScene3DEvent):void {
if (isShowingLargeImage) return;
var plane: Plane = e.displayObject3D as Plane;
//if (plane.extra.index != currentIndex) {
if (plane.extra.status != STATUS_ACTIVE) {
currentIndex = plane.extra.index;
arrangeThumbAt(currentIndex);
} else {
var imageDisplay: ImageDisplay = MovieClip(this.parent).imageLoader_mc as ImageDisplay;
imageDisplay.loadImage(plane.extra.image);
}
//}
}

private function createPlane(e: FileLoadEvent):void {
var mat: BitmapFileMaterial = e.target as BitmapFileMaterial;
var plane: Plane = new Plane(mat, mat.bitmap.width, mat.bitmap.height, 4, 4);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onOverPlane);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onOutPlane);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onPressPlane);
plane.extra = mat.extra;
plane.extra.status = STATUS_NORMAL;
planes.push(plane);
//reflect
var refBitmap: Bitmap = ReflectBitmap.getReflectBitmap(mat.bitmap, 100, 0.5);
refBitmap.cacheAsBitmap = true;
var refMat: BitmapMaterial = new BitmapMaterial(refBitmap.bitmapData);
refMat.smooth = true;
//refMat.doubleSided = true;
var refPlane: Plane = new Plane(refMat, refMat.bitmap.width, refMat.bitmap.height, 4, 4);
refPlane.extra = { };
//
default_scene.addChild(plane, "plane" + plane.extra.id);
default_scene.addChild(refPlane, "refPlane" + plane.extra.id);
//num ++;
/*if (num >= totalThumbs - 1) */arrangeThumb();
}

private function arrangeThumb():void {
for (var i:int = 0; i < planes.length; i++) {
var plane: Plane = planes[i] as Plane;
var rotationY: Number = 0;
if (i > 0)
{
rotationY = 35;
} else {
plane.extra.status = STATUS_ACTIVE;
}

var x = -100 + Math.cos(55 * (Math.PI / 180)) * 200 * i;
var z = Math.sin(55 * (Math.PI / 180)) * 200 * i;
var y = 0;
plane.extra.pos = { x: x, z: z };
var refPlane: Plane = current_scene.getChildByName("refPlane" + plane.extra.id) as Plane;
refPlane.extra.pos = { x: x, z: z };
Tweener.addTween(plane, { rotationY: rotationY, x: x, y: y, z: z, time: .5 , transition:"easeOutBack" } );
Tweener.addTween(refPlane, { rotationY: rotationY, x: x, y: y - refPlane.material.bitmap.height - 2, z: z, time: .5 , transition:"easeOutBack" } );
}
if (i == (totalThumbs - 1)) {
Tweener.addTween(current_camera, { z: -1000, x:0, time:6, delay:0.3, transition:"easeOutBack" } );
}
}

//
private function arrangeThumbAt(index: int):void {
for (var i:int = 0; i < planes.length; i++) {
var plane: Plane = planes[i] as Plane;
var dis: int = plane.extra.index - index;
var rotationY: Number = 0;

if (dis != 0)
{
rotationY = 35;
plane.extra.status = STATUS_TWEENING;
} else {
plane.extra.status = STATUS_ACTIVE;
}
var pos: int = 0;
if (dis > 0) {
pos = dis;
} else if (dis < 0) {
pos = planes.length + dis;
}

var x = -100 + Math.cos(55 * (Math.PI / 180)) * 200 * pos;
var z = Math.sin(55 * (Math.PI / 180)) * 200 * pos;
var y = 0;
plane.extra.pos = { x: x, z: z};
plane.extra.index = pos;

var refPlane: Plane = current_scene.getChildByName("refPlane" + plane.extra.id) as Plane;
refPlane.extra.pos = { x: x, z: z };

Tweener.removeTweens(plane);
Tweener.removeTweens(refPlane);
if (dis > 0) {
Tweener.addTween(plane, { rotationY: rotationY , x: x, z: z, time: 1.5 , transition:"easeOutBack", onComplete: turnNormal, onCompleteParams: [plane] } );
Tweener.addTween(refPlane, { rotationY: rotationY , x: x, z: z, time: 1.5 , transition:"easeOutBack"} );
} else if (dis < 0) {
Tweener.addTween(plane, {rotationY: rotationY , x: plane.x - 2500, z: plane.z - 2500, time: .8 , transition:"easeOutBack", onComplete: continue1, onCompleteParams: [plane]} );
Tweener.addTween(refPlane, {rotationY: rotationY , x: refPlane.x - 2500, z: refPlane.z - 2500, time: .8 , transition:"easeOutBack", onComplete: continue1, onCompleteParams: [refPlane]} );
} else {
Tweener.addTween(plane, { rotationY: rotationY , x: x, z: z, time: 1.5 , transition:"easeOutBack"} );
Tweener.addTween(refPlane, { rotationY: rotationY , x: x, z: z, time: 1.5 , transition:"easeOutBack"} );
}
}
}

private function continue1(plane: Plane):void {
plane.x = plane.extra.pos.x + 1000;
plane.z = plane.extra.pos.z + 1000;

Tweener.addTween(plane, {x: plane.extra.pos.x, z: plane.extra.pos.z, time: .7 , transition:"easeOutBack", onComplete: turnNormal, onCompleteParams: [plane]} );
}

private function turnNormal(plane: Plane):void {
plane.extra.status = STATUS_NORMAL;
}
}

}javascript:void(0)

CoverFlow AS3

package com.drca.coverflow { //com.drca.coverflow.CoverFlowManager
import blueroad.base.PaperBase;
import caurina.transitions.Tweener;
import com.pixelfumes.reflect.Reflect;
import flash.display.MovieClip;
import flash.net.getClassByAlias;
import gs.TweenMax;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.MovieAssetMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;

/**
* ...
* @author binhdocco
*/
public class CoverFlowManager extends PaperBase {
private var pics: Array = [new MOV_1(), new MOV_2(), new MOV_3(), new MOV_4(), new MOV_5()];// , new MOV_6(), new MOV_7()];
private var planes: Array = [];
//for tweener
private var time: Number = 1;
private const TRANSITION_ANI: String = "easeoutback";
//for position
private var distance: uint = 300;
private var roAngle: int = 60;
//camera position
private var camera_z: int = -850;
private var camera_y: int = 200;

public function CoverFlowManager() {
init(1024, 726);
}

override protected function init3d():void {
super.init3d();
for (var i:int = 0; i < pics.length; i++) {
//var linkageId: String = pics[i];

var mov: MovieClip = pics[i] as MovieClip;
new Reflect( { mc:mov, alpha:50, ratio:50, distance:0, updateTime:0, reflectionDropoff:1 } );
var mat: MovieMaterial = new MovieMaterial(mov, true);
mat.interactive = true;
mat.smooth = true;

//get width & height
var mc: MovieClip = MovieClip(mat.movie);
var plane: Plane = new Plane(mat, mc.width, mc.height, 10, 10);
plane.x = i * distance;
plane.y -= mc.height / 4;
plane.extra = { status: "normal", id: i };
planes.push(plane);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onClickPlane);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onOverPlane);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onOutPlane);
default_scene.addChild(plane);
}

default_camera.zoom = 6;
//default_camera.z = camera_z;
//default_camera.y = camera_y;

//show active plane
var activePlane: Plane = planes[Math.floor(planes.length/2)];
setPlaneActive(activePlane);
}

private function onOutPlane(e:InteractiveScene3DEvent):void {
viewport.buttonMode = false;
}

private function onOverPlane(e:InteractiveScene3DEvent):void {
viewport.buttonMode = true;
}

private function onClickPlane(e:InteractiveScene3DEvent):void {
var plane: Plane = e.displayObject3D as Plane;
switch (plane.extra.status) {
case "active":
zoomPlane(plane);
break;
case "zoom":
deZoomPlane(plane);
break;
case "normal":
setPlaneActive(plane);
break;
}
}

private function setPlaneActive(pic:Plane):void {
var id:Number = pic.extra.id;
var top:Number=-50;
var depth:Number;
var i:Number;
var dis:Number = distance / 3;
//TweenMax.to(pic, .5, { rotationY:0, rotationX:0, rotationY:0, x:0, z: -300, scale:1 } );
Tweener.addTween(pic, { time: time - 0.2, rotationY:0, rotationX:0, rotationY:0, x:0, z: -300, scale:1 });//, onComplete: zoomPlane, onCompleteParams: [pic] } );

for (i = id-1; i >=0; i--) {
dis += distance / (id - i);
depth = top + Math.abs(id - i) * 20;
planes[i].extra.status = "normal";
//TweenMax.to(planes[i], .5, { rotationY: -roAngle, x:0 - dis, z:depth } );
Tweener.addTween(planes[i], { time: time , rotationY: -roAngle, x:0 - dis, z:depth } );
}

dis = distance / 3;
i = 0;
for (i = id+1; i dis += distance / (i - id);
depth = top + Math.abs(id - i) * 20;
planes[i].extra.status = "normal";
//TweenMax.to(planes[i], .5, { rotationY:roAngle, x:0 + dis, z:depth } );
Tweener.addTween(planes[i], { time: time, rotationY:roAngle, x:0 + dis, z:depth } );
}
pic.extra.status = "active";
}

private function zoomPlane(pic:Plane):void {
var o:Number = 0;
//TweenMax.to(pic, .5, { z: -600, rotationY:o } );
Tweener.addTween(pic, { time: .7, z: -650, rotationY:o , transition: TRANSITION_ANI} );
pic.extra.status = "zoom";
}

private function deZoomPlane(pic:Plane):void {
//TweenMax.to(pic, .5, { z: -300, rotationY:0 } );
Tweener.addTween(pic, { time: time, z: -300, rotationY:0 , transition: TRANSITION_ANI} );
pic.extra.status = "active";
}
}

}

CoverFlow AS2

import blueroad.paper.BasePaper;
import caurina.transitions.Tweener;
import com.drca.reflect.ReflectionAS2;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.Plane;
import org.papervision3d.Papervision3D;
/**
* ...
* @author binhdocco
*/
class blueroad.coverflow.CoverFlowManager extends BasePaper {
private var mov1_mc: MovieClip;
private var mov2_mc: MovieClip;
private var mov3_mc: MovieClip;
private var mov4_mc: MovieClip;
private var mov5_mc: MovieClip;

private var pics: Array;
private var planes: Array = [];
//for tweener
private var time: Number = 1;
private var TRANSITION_ANI: String = "easeoutback";
//for position
private var distance: Number = 300;
private var roAngle: Number = -60;

public function CoverFlowManager() {

}
public function onLoad() {
init();
}
public function init3d() {
//trace("planes.length : " + planes.length);
pics = [mov1_mc, mov2_mc, mov3_mc, mov4_mc, mov5_mc];
planes = [];
for (var i:Number = 0; i < pics.length; i++) {
//var linkageId: String = pics[i];

var mov: MovieClip = pics[i];
new ReflectionAS2( { mc:mov, alpha:40, ratio:70, distance:0, reflectionDropoff:1 } );
mov._visible = false;
//trace("mov : " + mov);
//new Reflect( { mc:mov, alpha:50, ratio:50, distance:0, updateTime:0, reflectionDropoff:1 } );
var mat: MovieMaterial = new MovieMaterial(mov, true);
mat.oneSide = false;
mat.smooth = true;
//get width & height
var plane: Plane = new Plane(mat , mov.width, mov.height, 10, 10);
plane.x = i * distance;
plane.y += mov._height / 4;
plane.extra = { status: "normal", id: i };
planes.push(plane);
//plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onClickPlane);
//plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onOverPlane);
//plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onOutPlane);
scene.push(plane);
//plane.container.onRelease = Relegate.create(this, onClickPlane, plane);
}
setEvents();
}

private function setEvents():Void {
//clearInterval(this.interval);
for (var i:Number = 0; i < planes.length; i++) {
var plane: Plane = Plane(planes[i]);
plane.container.onRelease = Relegate.create(this, onClickPlane, plane);
}
//show active plane
var activePlane: Plane = planes[Math.floor(planes.length / 2)];
setPlaneActive(activePlane);
}

private function onClickPlane(e:Plane):Void {
var plane: Plane = Plane(e);
switch (plane.extra.status) {
case "active":
zoomPlane(plane);
break;
case "zoom":
deZoomPlane(plane);
break;
case "normal":
setPlaneActive(plane);
break;
}
}

private function setPlaneActive(pic:Plane):Void {

var id:Number = pic.extra.id;
var top:Number=-50;
var depth:Number;
var i:Number;
var dis:Number = distance / 3;
//tracePos(pic);
//TweenMax.to(pic, .5, { rotationY:0, rotationX:0, rotationY:0, x:0, z: -300, scale:1 } );
Tweener.addTween(pic, { time: time - 0.2, rotationY:0, rotationX:0, rotationY:0, x:0, z: -300, scale:1 } );// , onComplete: tracePos, onCompleteParams: [pic] } );

for (i = id-1; i >=0; i--) {
dis += distance / (id - i);
depth = top + Math.abs(id - i) * 20;
planes[i].extra.status = "normal";
//TweenMax.to(planes[i], .5, { rotationY: -roAngle, x:0 - dis, z:depth } );
Tweener.addTween(planes[i], { time: time , rotationY: -roAngle, x:0 - dis, z:depth} );
}

dis = distance / 3;
i = 0;
for (i = id+1; i dis += distance / (i - id);
depth = top + Math.abs(id - i) * 20;
planes[i].extra.status = "normal";
//TweenMax.to(planes[i], .5, { rotationY:roAngle, x:0 + dis, z:depth } );
Tweener.addTween(planes[i], { time: time, rotationY:roAngle, x:0 + dis, z:depth} );
}
pic.extra.status = "active";
}

private function zoomPlane(pic:Plane):Void {
var o:Number = 0;
//TweenMax.to(pic, .5, { z: -600, rotationY:o } );
Tweener.addTween(pic, { time: .7, z: -650, rotationY:o , transition: TRANSITION_ANI} );
pic.extra.status = "zoom";
}

private function deZoomPlane(pic:Plane):Void {
//TweenMax.to(pic, .5, { z: -300, rotationY:0 } );
Tweener.addTween(pic, { time: time, z: -300, rotationY:0 , transition: TRANSITION_ANI} );
pic.extra.status = "active";
}

private function tracePos(pic:Plane):Void {
trace("===== pic : " + pic.container);
trace("pic x : " + pic.x);
trace("pic y : " + pic.y);
trace("pic z : " + pic.z);
}
}

Thursday, February 5, 2009

Moving Data from Production to Sandbox

I just spent the afternoon tearing my hair out over what really should have been a simple process. Gotta love a learning curve!!

I have a client that’s on the old NPSF template and I’m planning to upgrade them to the new template – but I wanted to try it out in a sandbox first so I didn’t have an “surprises”. I thought this would be a piece of cake. Here’s what I learned (oh, and no, I haven’t even gotten to installing the new packages yet!):

  1. First, Setup new Sandbox: But wait… with the Non Profit license that Salesforce donates, you don’t get the option of creating a sandbox with data; you can create a developer sandbox, which creates your exact SF configuration, but without data. That’s helpful, but only sort of. I need to see what the effects of installing the new packages are on the DATA. So, I thought, no problem, I’ll just export the objects in use to .csv files and import them back into the sandbox…

  1. Next challenge: I got the data out just fine, (I used Apex Data loader v14) but then I needed to figure out how to get the data back into the sandbox. After a bit of poking around online, I found that to do this you have to make a change to the Data Loader settings. Change server host to: https://test.salesforce.com, (it’s https://www.salesforce.com for production databases), then log into your sandbox database using your sandbox username and password + sequrity token (note this is not the same sequrity token you use for your production db, you’ll need to re-set it, (Setup | My Personal Information | Reset My Sequrity Token) before you do this.

  1. More Hair Pulling: OK, now I can load data into my Sandbox, and I load up the Organizations/Accounts file. Everything goes in OK except the one record that’s the ‘Individual’ Account record that so many contacts are linked to. I get the following error – “Record Type: id value not valid for the users profile: 012700000009SZlAAM”. Hmmm… I’m System Administrator. I go to Setup | Manage Users | Profiles - Click on System Administrator. Scroll down to Record Type Settings; click on Edit in the Accounts section. Move Individual over from Available Record Types into Selected Record Types; click OK; try import on ‘Individual’ account into Orgs again – it works!

  1. Next Headache: “insufficient access rights on cross-reference id”!! So. I guess I thought this process would be easy because I could just import the object data from the production instance and since the id’s were all nicely linked, it would be a simple process, but what I quickly realized is that when you import data for say, Organizations, Salesforce replaces the ID – and if you say, tried to import Contacts with the field ID (from production), you’ll get the “insufficient access rights on cross-reference ID” message. This all makes perfect sense now that I think about it – of course ID’s are auto-generated fields and would have to be re-created in a new db. Here’s a sketch of my process:

    1. Create LegacyID fields (text 35) in Organizations, Contacts, Households, Donations
    2. Prepare Organization import file: rename ID field as LegacyID
    3. Import Organization data
    4. Extract Organization data with ID, Name, LegacyID (I don’t know why I think I need name, I guess it’s just reassuring to have it in the midst of all those weird numbers)
    5. Prepare Household import file: rename ID field as LegacyID
    6. Import Household data
    7. Extract Household data with ID, Name, LegacyID
    8. Prepare Contacts import data file: rename ID field as LegacyID, replace ID’s for Organization(AccountID) and Household (ONW_Household?) with new ID’s from export files using VLookup
    9. Import Contacts data
    10. Extract Contacts data with ID, Last Name, LegacyID
    11. Prepare Donations import file: rename ID field as LegacyID, replace AccountID with new ID’s from export file using VLookup
    12. Import Donations data
    13. Extract Donations; ID, Name, LegacyID
    14. Prepare OpportunityContactRoles import file: delete ID field (no need for LegacyID); replace ContactID and OpportunityID with new values from export files using VLookup
    15. Import OpportunityContactRoles
    16. Prepare Connections import file; delete ID, replace ContactID’s and OrganizationID’s in the following fields with data from export files using VLookup (RELATED_CONTACT__C, CONTACT__C, RELATED_ORGANIZATION__C)

That should do it. Whew. A lot more work than I’d planned on. Time to do this once I’d understood the process? About 1 hour (small org <>


source : http://ceenotes.wordpress.com/2009/01/28/moving-data-from-production-to-sandbox/