Created
December 9, 2016 15:42
-
-
Save jsmithdev/69c5e26f98fe651a7836b61666b093bc to your computer and use it in GitHub Desktop.
EXAMPLE ONLY: DML on load of VF page, which technically you're not supposed to do but that makes it fun... More @ https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ' ### You'll need something like this in your visual force page, main focus being action="{!markActiveDetails}" ### | |
' <apex:page docType="html-5.0" action="{!markActiveDetails}" standardController="Service_Inquiry_SP__c" recordSetVar="sit" extensions="ServiceInquiryOSPExt" standardStylesheets="false" sidebar="false"> | |
' </apex:page> | |
*/ | |
public PageReference markActiveDetails(){ | |
System.debug('#$#$# markActiveDetails running with siId ' + siId); | |
List<Service_Inquiry_Details__c> deetsToUpdate = new List<Service_Inquiry_Details__c>(); | |
Set<String> speedList = new Set<String>(); | |
Set<String> locList = new Set<String>(); | |
Boolean wasThisNeeded = false; | |
List<Service_Inquiry_Details__c> siDetails = [ | |
SELECT Id, ServiceLocationStreet__c, Active__c, Service_Location__c, Cost_Line__c, Speed__c | |
FROM Service_Inquiry_Details__c | |
WHERE Service_Inquiry__c = :siId | |
ORDER BY ServiceLocationStreet__c | |
]; | |
for(Service_Inquiry_Details__c d : siDetails){ | |
if(!locList.contains(d.ServiceLocationStreet__c)){ | |
system.debug('#$#$# NEW STREET ' + d.ServiceLocationStreet__c); | |
locList.add(d.ServiceLocationStreet__c); | |
d.Active__c = true; | |
speedList = new Set<String>(); | |
} | |
if(!speedList.contains(d.Speed__c)){ | |
system.debug('#$#$# NEW SPEED ' + d.Speed__c); | |
speedList.add(d.Speed__c); | |
if(d.Cost_Line__c != true){ | |
d.Cost_Line__c = true; | |
deetsToUpdate.add(d); | |
} | |
} | |
} | |
if(deetsToUpdate.size() > 0){ | |
wasThisNeeded = true; | |
} | |
if(wasThisNeeded){ | |
system.debug('#$#$# Updating deets size: '+ deetsToUpdate.size() +' Was This Needed? '+ wasThisNeeded); | |
update deetsToUpdate; | |
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); | |
pageRef.setRedirect(true); | |
return pageRef; | |
} | |
else { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment