Reply
Regular Visitor
Tilak De
Posts: 2
0
Accepted Solution

Dynamic Insert Query

Let me first describe the requirement -

 

I have a managed package that contains an Object called Student. I have to create a many-to-many relationship with another object. I have a junction object for this.

Just imagine, that this package can get installed into different orgs, and the many-to-many relationship can happen with some object called Class or Teacher or Exam (depending on the requirement of the org.)

 

I am creating the second master-detail relationship of the junction object when I have installed the package in the org, and I am storing the API name of the second master-detail relationship in a Custom Settings. (Custom settings also belong to my package)

 

The Student-Teacher or Student-Exam, assignment is happening from a VF page(also belonging to the package). So I need to dynamically select the field API name of the second master-detail, assign value to it and save it.

 

Is there any way to create a Dynamic Insert DML? 

 

Trusted Contributor
colemab
Posts: 485
0

Re: Dynamic Insert Query

What do you mean by "dynamically select the field API name of the second master-detail"?  Don't you have this stored in your custom setting?

 

Maybe you are looking for the describe methods.

--------------------------------------------------------------
Salesforce.com Certified Advanced Administrator
http://www.forcedisturbances.com/

Regular Visitor
Tilak De
Posts: 2
0

Re: Dynamic Insert Query

Yes. I have it stored in Custom Settings. But the value in the custom settings will change from org to org. So the value that I will be querying from the Custom Settings needs to supplied to the DML insert. So the DML will have the second-master-details API name being taken from the Custom Settings dynamically.

 

Indeed I am looking for some Schema method, that might provide us this flexibility for DML Insert, but I am not able to figure out the correct approach.

 

Any help is much appreciated.

Trusted Contributor
colemab
Posts: 485
0

Re: Dynamic Insert Query

If you are looking for an example that details some of the schema / describe methods, please see my blog post here.  The post contains a link to the git hub repository that contains the code.

 

The post is on how to create a visual force component that will take an object coming in and using the describe methods will display all of the fields on that object for the purposes of building a SOQL where clause.

 

Hopefully that will give you a good intro to how the methods can be used.

--------------------------------------------------------------
Salesforce.com Certified Advanced Administrator
http://www.forcedisturbances.com/

Trusted Contributor
colemab
Posts: 485
0

Re: Dynamic Insert Query

Also, you might find the "Setting and Retrieving Field Values" section of this page interesting.

--------------------------------------------------------------
Salesforce.com Certified Advanced Administrator
http://www.forcedisturbances.com/