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
john8407john8407 

Multiple objects in Visualforce page

I have a visualforce page that shows fields from multiple objects.  I noticed that when I try to save, it is not saving to the other child objects.  Anyone know how to make this happen?

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

I would assume that if you are using the standard {!save} function it is only saving the information related to the standard controller.

 

To save across multiple objects, you will need to create a custom save function. In that functions:

 

1. I assume you already have the specific lists related to each object defined and are using <apex:inputfield> to get the input from the user, or <apex:outputField> and allowing editing??

 

2. In the custom save function insert or upsert as appropriate.

 

Posting your code may help to better understand what you are trying to accomplish

All Answers

Starz26Starz26

I would assume that if you are using the standard {!save} function it is only saving the information related to the standard controller.

 

To save across multiple objects, you will need to create a custom save function. In that functions:

 

1. I assume you already have the specific lists related to each object defined and are using <apex:inputfield> to get the input from the user, or <apex:outputField> and allowing editing??

 

2. In the custom save function insert or upsert as appropriate.

 

Posting your code may help to better understand what you are trying to accomplish

This was selected as the best answer
johnc82johnc82

starz...Do you know what I have wrong here? It's modifying the record but not saving anything to it.

 

 

 

public class ABCcontrollers{ 
ApexPages.StandardController controller;


Public ABCcontrollers(ApexPages.StandardController stdController) {}
    public void saveabc()
    {
    String sId = ApexPages.currentPage().getParameters().get('id');
        ABC__C ab = [SELECT Id FROM ABC__c WHERE Id= :sId];
        if (ab != null) {
        update ab;

}

}

}

Starz26Starz26

I would assum that you are noe getting the new sow data from the record, you select pulles data from the database but what was entered on the page has not be committed yet???

 

Here is what I did on my form:

 

 

public Pagereference iSave(){
        

   //conn was already declared as part of the init() function so the data entered into the form was entered into the object reference conn

        conn.RecordTypeId = rt.id;
        conn.OwnerId = UserInfo.getUserId();
        
        
        insert conn; 
        
            ApexPages.Message msgErr = new ApexPages.Message(ApexPages.Severity.INFO, 'Your Contact ' + conn.FirstName +' ' + conn.LastName + ' was added with the id ' + conn.id);
            ApexPages.addmessage(msgErr);
            
        conn = New Contact(); //this reset the form data to a new record when saved

    }
    return null;

}

 

johnc82johnc82

It's a page that pulls from 8 different objects.  It's already created and when I enter data in the fields and save with the code I posted, it doesnt post to the record, but the last modified date is updating.  So I'm not sure what I have wrong?

johnc82johnc82

Do you know how I would do this for Update?