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

Using apex to load detail view, OR create new record if none exists, for custom object data?

Hi all,


I think this is simple, but can't quite figure it out. Here's the use case:


A teacher has links to lesson plans (an object), 1-10, each residing in a different area of the page. Each lesson plan link sends the following to a new page:


Curriculum ID (Lesson_Plans lookup relation), Contact (owner) and number (1-10, since each renders a different template). 


I'm trying to build a controller extension so that Lessons either loads the right detail view (pre-populated with the right information, if it exists) OR creates a new record with the information in the URL string, e.g., curriculum ID, contact owner and lesson number. 


Any ideas / suggestions on how to make this happen? 




Public detailObject__c fobjDetail{


          if(fobjDetail  == null){

                 detailObject__c fobjDetail = new detailObject__c();

                 List<detailObject__c> flstDetailObject = new List<detailObject__c>([select id from detailObject__c where pid__c = : ApexPages.currentPage().getParameters().get('pid')]);


                 if(flstDetailObject.size() > 0)

                          fobjDetail   = flstDetailObject[0];


                          insert fobjDetail;




          return fobjDetail;




          fobjDetail = value;