Last active
March 6, 2020 21:18
-
-
Save peterknolle/4761339 to your computer and use it in GitHub Desktop.
Visualforce Remoting with Relationships
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="RemotingController"> | |
<script type="text/javascript"> | |
function Test_Object__c() { | |
this.Name = ''; | |
this.Test_Object_2__r = null; | |
} | |
function Test_Object_2__c() { | |
this.Name = ''; | |
} | |
var b = new Test_Object_2__c(); | |
b.Name = 'New B'; | |
var a = new Test_Object__c(); | |
a.Name = 'New A'; | |
a.Test_Object_2__r = b; | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.RemotingController.UpsertA}', | |
a, | |
function(result, event) { | |
console.log(result); | |
} | |
); | |
</script> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class RemotingController { | |
// Assumes two custom objects: Test_Object__c with lookup to Test_Object_2__c | |
@RemoteAction | |
global static void UpsertA(Test_Object__c obj1) { | |
upsert obj1.Test_Object_2__r; | |
obj1.Test_Object_2__c = obj1.Test_Object_2__r.Id; | |
upsert obj1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment