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

Copying from Standard object to Custom object in Apex

I'm trying to display some Standard object (Contracts, Products) data on the Customer portal. But as we cannot display those details directly on the customer portal, I was told that we can copy the data from that object and save it on a Custom Object and then display that.


But the problem is that I have contracts and products linked via a custom object already. What I want to do it first perform a query in Apex, and then save the result of that query on to a object (By save I mean copy and not save a reference) that I can then display on the customer portal.


I have tried using dynamic DML to do it, but then again, it wasn't working. Any other way?


You should be able to define a custom schema (custom objects/relationships) which you can simply leverage as a UI rendering mechanism.  If you don't need to persist the data, you can simply perform the queries against the standard objects and then copy/push this data into your custom schema and bind to this in your VF pages.  Alternatively you can save this data to the custom schema, but this will potentially double your storage cost for these records.  The describe framework will allow you to dynamically iterate through the fields.  You can leverage the sobject.get and sobject.put to copy the data over from the standard to the custom schema.


Can you give me an example. I'm fairly new to Apex.