You need to sign in to do that
Don't have an account?
eworks123456
SHARE:I want to share basic dml(insert..) functionality on sales-force objects with community
Hello Team,
I want to share basic dml functionality on sales-force objects, I hope this will help you all.
Regards,
Manoj Jain
Page Code: <apex:page controller="todayDML"> <script type="text/javascript"> function saveAlert() { alert("record has been saved successfully"); setTimeout("location.reload(true);"); } function deleteAlert() { alert("record has been deleted successfully"); setTimeout("location.reload(true);"); } function modifyAlert() { alert("record has been modified successfully"); setTimeout("location.reload(true);"); } function removeAllAlert() { alert("All record has been deleted successfully"); setTimeout("location.reload(true);"); } </script> <apex:messages /> <apex:form > <apex:panelGrid columns="2"> Name: <apex:inputText value="{!dName}" /> Last Name: <apex:inputText value="{!lName}"/> Summary: <apex:inputText value="{!sum}"/> </apex:panelGrid> <br/><br/> <apex:commandButton value="Save" action="{!save}" oncomplete="saveAlert()" /> <apex:commandButton value="Update" action="{!updateDml2}" oncomplete="modifyAlert();"/> <apex:commandButton value="Delete" action="{!delete1}" oncomplete="deleteAlert();"/> <apex:commandButton value="Remove All" action="{!removeAll}" oncomplete="removeAllAlert();"/> <apex:commandButton value="Search" action="{!doSearch}" rerender="block1" status="status"/> <apex:commandButton value="Reset" action="{!reset}"/><br/><br/> </apex:form> <apex:form > <apex:pageBlock id="block1"> <apex:actionStatus id="status" startText="requesting..."/> <apex:pageBlockTable value="{!dataDml}" var="da" rendered="{!NOT(ISNULL(dataDml))}"> <apex:column value="{!da.name}"/> <apex:column value="{!da.Last_Name__c}"/> <apex:column value="{!da.Other__c}"/> <apex:column value="{!da.dml1__r.name}"/> <apex:column value="{!da.dml1__r.Summary__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page> Controller Code: public class todayDML { public String dName{get; set;} public String lName{get; set;} public String sum{get; set;} public String valueOne{get; set;} public void save() { dml1__c d1 = new dml1__c( name = dName, Summary__c = sum ); insert d1; dml2__c d2 = new dml2__c( name = dName, Last_Name__c = lName, Other__c = sum, dml1__c = d1.id ); insert d2; //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Bill-To Sites successfully created')); } public void updateDml2() { List<dml2__c> d2 = [SELECT id,name, Last_Name__c, Other__c,dml1__c FROM dml2__c WHERE name =: dName]; List<dml1__c> d1 = [SELECT Id, Summary__c FROM dml1__c]; for(dml2__c dm2 : d2) { dm2.Last_Name__c = lName; dm2.Other__c = sum; for(dml1__c dm1 : d1) { if(dm1.Id == dm2.dml1__c)dm1.Summary__c = sum; } } update d2; update d1; } public void delete1() { dml1__c[] d1 = [select name from dml1__c where name =: dName limit 50]; dml2__c[] d2 = [select name from dml2__c where name =: dName limit 50]; try { delete d1; delete d2;} catch (DmlException e){ System.debug(e);} } public void removeAll() { dml1__c[] d1 = [select name from dml1__c]; dml2__c[] d2 = [select name from dml2__c]; try { delete d1; delete d2;} catch (DmlException e){ System.debug(e);} } List<dml2__c> dataDml; public List<dml2__c> getDataDml(){ return dataDml; } public PageReference doSearch(){ dataDml = [select name, Last_Name__c, Other__c,dml1__r.name, dml1__r.Summary__c from dml2__c where name =: dName]; return null; } public void reset(){ dName = ''; lName = ''; sum = ''; } }