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
oceanofstarsoceanofstars 

Need help in Save button

Need help in save button: Whenwhen we are saving the records in VF page we are able to see the values but when we open the record again and see we are unable to see the values. This is my class 

 

public class SSOWcontrollers{ 

ApexPages.StandardController controller;
Public SSOW__c ssow;
Public SSOWcontrollers(ApexPages.StandardController stdController) {}
    public void savessow()
    {
    String sId = ApexPages.currentPage().getParameters().get('id');
        SSOW__C sow = [SELECT Id FROM SSOW__c WHERE Id= :sId];
        if (sow != null) {
        update sow;
        }
        HVoIP__c hv = [SELECT Id FROM HVoIP__c WHERE SSOW__c = :sId];
        if (hv != null) {
        update hv;
        }
        VoIP__c v = [SELECT Id FROM VoIP__c WHERE SSOW__c = :sId];
        if (v != null) {
        update v;
        }
        VLS__c vl = [SELECT Id FROM VLS__c WHERE SSOW__c = :sId];
        if (vl != null) {
        update vl;
        }
        VPN__c vp = [SELECT Id FROM VPN__c WHERE SSOW__c = :sId];
        if (vp != null) {
        update vp;
        }
        EIA__c e = [SELECT Id FROM EIA__c WHERE SSOW__c = :sId];
        if (e != null) {
        update e;
        }
        DIA__c d = [SELECT Id FROM DIA__c WHERE SSOW__c = :sId];
        if (d != null) {
        update d;
        }
        Managed_Network_Security__c mns = [SELECT Id FROM Managed_Network_Security__c WHERE SSOW__c = :sId];
        if (mns != null) {
        update mns;
        }
        Managed_Router__c mr = [SELECT Id FROM Managed_Router__c WHERE SSOW__c = :sId];
        if (mr != null) {
        update mr;
        }
     }

}
     Here is the part of the vf page where i created a save button

 

<apex:pageBlockButtons location="TOP" > 

<apex:commandButton id="theButton" action="{!savessow}" value="save"  />           

</apex:pageBlockButtons>    

mngmng

Are you updating the related records? Save would only save changes you've made to the SSOW__c object that the page is open for. You'll need to manually go through the related records and do DMLs for each related object.

oceanofstarsoceanofstars

Yes we are updating the related record.  If you look in the code Hvoip is lookup in SSOW and SSOW is lookup in Hvoip. So its one to one relation. Can you please give me an example how to give manually go through the related records and do DMLs for each related object . Really appreciate your help

mngmng

I apologize for misreading the post. I had actually thought it was something else and my reply kind of shows that....

But anyways!

 

From what the apex is showing right now, the records that you choose to update are records that are being pulled in from the database. Therefore, those records won't have any information that got submitted from the VisualForce page. At this point, I don't even know how you're getting values from the VF page at all, since you're not showing any kind of properties in the controller.

 

In a nutshell, you'll want to query for the related records in the controller, and keep references to those related records as properties, with getters/setters. That way, when you submit the VF page back to the controller, the values will persist in those related records. Then, the save method will just do dml on those records. Your controller will ultimately have something like this...

public class SSOWcontrollers { 

	private ApexPages.StandardController controller;
	public SSOW__c ssow;

	// properties
	public HVoIP__c relatedHVoIP { get; set; }
	public VoIP__c relatedVoIP { get; set; }
	/*
		etc for all related objects
	*/
	
	public SSOWcontrollers(ApexPages.StandardController stdController)
	{
		this.ssow = stdController.getRecord();
		
		relatedHVoIP = [ SELECT Id, /* any exposed fields go here too */ FROM HVoIP__c WHERE SSOW__c = :this.ssow.Id ];
		relatedVoIP = [ SELECT Id, /* any exposed fields go here too */ FROM VoIP__c WHERE SSOW__c = :this.ssow.Id ];
		
		/*
			etc
		*/
	}
	
	public void saveSSOW()
	{
		System.SavePoint savePoint = Database.setSavePoint();
		try
		{
			update relatedHVoIP;
			update relatedVoIP;
			
			/*
				etc
			*/
		}
		catch( System.DmlException ex )
		{
			Database.rollback( savePoint );
			ApexPages.addMessages( ex );
		}
	}
}

 

Just remember to expose the related records in the VF page, and that for every field you'll need to modify the query for the related object.

oceanofstarsoceanofstars

Thanks for replying back with a sample code. I really appreciate your help. I tried with your code i have some problems pasted below. please let me know on this

 

This line is throing the error

Illegal assignment from SObject to SOBJECT:SSOW__c at line 16 column 9

 

this.ssow = stdController.getRecord();

 

Then i tried this one instead of above line. The code is saved but unable to save it in database.

String sId = ApexPages.currentPage().getParameters().get('id');