+ Start a Discussion
Pablo LamasPablo Lamas 

Saving records one at a time

Hello,
So I am having a bit of an issue when trying to save changes on fields that I have made inline editable within my visualforce class. It all displays correctly and I can click on everything I need, but when I hit save, it causes an issue with one of the triggers we have that states that only one record at a time can be saved. I was told to traverse the list and save as it traverses and that would solve it, turns out that is not an option as well since it will hit the limits of a package that we have installed. So I was left with thinking if this is plausible through other means? Would a javascript script work to save indivual records at at time and not triger either of the issues I have stated? Any assistance would be greatly appreciated. 

VF Page
-------------------------
<apex:page standardController="Installation__c" extensions="InlineEditingController" recordSetVar="Installation" >

    <apex:form >
        <apex:pageBlock title="Edit Report">
                      
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!cancel}" value="Cancel" />
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!records}" var="rec">                  
                <apex:column value="{!rec.Expected_Rebate_Amount__c}"></apex:column>            
                <apex:column value="{!rec.Opportunity__r.Name}"></apex:column>
                <apex:column value="{!rec.Name}"></apex:column>  
                <apex:column value="{!rec.Rebate__r.Name}"></apex:column>  
                <apex:column value="{!rec.Phone_Numbers__c}"></apex:column>  
                <apex:column value="{!rec.Email__c}"></apex:column>
                    <apex:column headerValue="*Rebate Status">
                        <apex:outputField value="{!rec.Rebate__r.Rebate_Status__c}">
                            <apex:inlineEditSupport event="ondblclick" showOnEdit="update"/>
                        </apex:outputField>
                    </apex:column>
                    <apex:column headerValue="*Initial Interconnection Submitted Date">
                        <apex:outputField value="{!rec.Rebate__r.Net_Metering_Submitted__c}">
                            <apex:inlineEditSupport event="ondblclick" showOnEdit="update"/>
                        </apex:outputField>
                    </apex:column>
                    <apex:column value="{!rec.Elect_Co__c}"></apex:column>  
                    <apex:column value="{!rec.Job_Site_Street_Address__c}" ></apex:column>  
                    <apex:column value="{!rec.System_Size__c}"></apex:column>          
                    <apex:column value="{!rec.Days_Aging__c}"></apex:column>     
                    <apex:column value="{!rec.Rebate_Notes__c}"></apex:column> 

                    <apex:column value="{!rec.Total_Cost_of_Install__c}"></apex:column> 
            </apex:pageBlockTable>
         
            <apex:panelGrid cellpadding="5" cellspacing="5" columns="5" >
                <apex:commandButton value="|<" action="{!first}"  />
                <apex:commandButton value="<" action="{!previous}" rendered="{!HasPrevious}" />
                <apex:commandButton value=">" action="{!next}" rendered="{!HasNext}" />
                <apex:commandButton value=">|" action="{!last}"  />   
           </apex:panelGrid>
           
         </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
------------------
public class InlineEditingController{
    public List<Installation__c> records {get;set;}
   
    public InlineEditingController(ApexPages.StandardSetController setCon){
        records = [SELECT Id, Name, Expected_Rebate_Amount__c,Opportunity__r.Name, Rebate__r.Name, Phone_Numbers__c, Email__c, Rebate__r.Rebate_Status__c, Rebate__r.Net_Metering_Submitted__c, Elect_Co__c,Job_Site_Street_Address__c,System_Size__c,Days_Aging__c, Rebate_Notes__c, Total_Cost_of_Install__c FROM Installation__c WHERE Initial_Interconnection_Submitted__c = null AND (Install_Status__c = 'Design' OR Install_Status__c = 'Permit Submitted' OR Install_Status__c = 'Permit Revisions Needed' OR Install_Status__c = 'Permit Ready to be Picked Up' OR Install_Status__c = 'Permit Picked Up/Schedule Install' OR Install_Status__c = 'Install Scheduled with Customer' OR Install_Status__c = 'Installation in Process' OR Install_Status__c = 'Install Complete - Pending Local Inspections' OR Install_Status__c = 'Install Complete - Pending PTO' OR Install_Status__c = 'Install Complete - Pending Final Approvals') AND Opportunity__r.RecordType.Name = '1LE Commercial Sales'];
    }
    
    public PageReference save(){
        for(Installation__c i : records){          
            update records;
        }
        return null;   
    }
 }
 
Best Answer chosen by Pablo Lamas
Maharajan CMaharajan C
Hi Pablo,

Change the below line: 

But if more than 150 records then it will hit limit

 public PageReference save(){
        for(Installation__c i : records){          
            update i;
        }
        return null;   
    }
 }

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj.

All Answers

Maharajan CMaharajan C
Hi Pablo,

Change the below line: 

But if more than 150 records then it will hit limit

 public PageReference save(){
        for(Installation__c i : records){          
            update i;
        }
        return null;   
    }
 }

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj.
This was selected as the best answer
Pablo LamasPablo Lamas
That seemed to do the trick! I had done something like that before but I had implemented it incorrectly. Thank you for the assistance Raj!
Pablo LamasPablo Lamas
Raj,
So upon testing some of the fields it seems that the one of my fields(Intial Interconnection) will save the date i enter but will not update the record. The other field I have will not save the change on the visualforce page or the actual record. Any idea as to why that is occuring?