Created
December 13, 2016 03:52
-
-
Save Sunil02kumar/e62f016fd9cfcd09bd20fa6dd2cff5c6 to your computer and use it in GitHub Desktop.
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
| public class SOQLInjectionDemoController { | |
| public String name {get;set;} | |
| public String queryString{get;set;} | |
| public List<Account> accList{get;set;} | |
| public SOQLInjectionDemoController (){ | |
| accList = new List<Account>(); | |
| } | |
| public PageReference query() { | |
| if(name !=null && name !=''){ | |
| accList = new List<Account>(); | |
| queryString= 'SELECT Id, name, industry, BillingStreet, BillingState, BillingCity, BillingCountry FROM Account WHERE ' + | |
| ' Name like \'%' + name + '%\''; | |
| accList = Database.query(queryString); | |
| }else{ | |
| ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter search text value')); | |
| } | |
| return null; | |
| } | |
| } |
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
| <apex:page controller="SOQLInjectionDemoController"> | |
| <apex:form > | |
| <apex:pageMessages /> | |
| <apex:outputText value="Name" /> | |
| <apex:inputText value="{!name}" /> | |
| <apex:commandButton value="Search Account" action="{!query}" /> | |
| <br/> <br/> | |
| <apex:outputLabel value="Query String"/> | |
| <apex:outputText value="{!queryString}"/> | |
| <br/> <br/> | |
| <apex:pageBlock title="Search Results"> | |
| <apex:pageBlockTable value="{!acclist}" var="acc"> | |
| <apex:column headerValue="Name"> | |
| <apex:outputtext value="{!acc.name}"/> | |
| </apex:column> | |
| <apex:column headerValue="Industry"> | |
| <apex:outputtext value="{!acc.industry}"/> | |
| </apex:column> | |
| <apex:column headerValue="Billing Address"> | |
| <apex:outputtext value="{!acc.BillingStreet} {!acc.BillingCity},{!acc.BillingState}, {!acc.BillingCountry}"/> | |
| </apex:column> | |
| </apex:pageBlockTable> | |
| </apex:pageBlock> | |
| </apex:form> | |
| </apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment