1

I have made changes in vf page as,

<apex:page controller="CSRF_Challenge" sidebar="false" tabStyle="CSRF_Challenge__tab">
<apex:sectionHeader title="CSRF Challenge" />
<apex:form >
    <apex:pageBlock >
        <apex:pageMessages />      
        <apex:pageBlockSection title="Demo" columns="1" id="tableBlock">

            <apex:pageBlockTable value="{!Requisitions}" var="req">
                <apex:column headervalue="Castle">
                    <apex:outputfield value="{!req.Castle__c}" />
                </apex:column>             
                <apex:column headervalue="Resource">
                    <apex:outputfield value="{!req.Resource__c }" />
                </apex:column> 
                <apex:column headervalue="Quantity">
                    <apex:outputfield value="{!req.Quantity__c}" />
                </apex:column>
                <apex:column headervalue="Name">
                    <apex:outputfield value="{!req.Name}" />
                </apex:column> 
                <apex:column headervalue="Approved">
                    <apex:outputfield value="{!req.Approved__c}" />
                </apex:column>                                                  
               <apex:column headervalue="Approval Action">
                    <apex:outputLink target="_new" value="/apex/CSRF_Challenge?approve={!req.id}">Approve This Requisition</apex:outputLink>
                </apex:column>
                <apex:column headervalue="Approval Action (NO CSRF)">
                    TBD
                    <!-- complete challenge here -->
                    <apex:commandLink value="Approve This Requisition" action="{!approveReqNOCSRF}"> <apex:param name="accId" value="{!req.id}" assignTo="{!approve}"/> </apex:commandLink>
                </apex:column>                                                                                               
            </apex:pageBlockTable>

        </apex:pageBlockSection>
        <apex:pageBlockSection title="Code links" columns="1">
            <apex:outputPanel >
                <ul>
                    <li><c:codeLink type="Visualforce" namespace="" name="CSRF_Challenge" description="Visualforce Page"/></li>            
                    <li><c:codeLink type="Apex" namespace="" name="CSRF_Challenge" description="Apex Controller"/></li>
                </ul>
            </apex:outputPanel>        
        </apex:pageBlockSection>        
    </apex:pageBlock>          
</apex:form>              
</apex:page>

and my controller class is -

public class CSRF_Challenge {

    public String req { get; set; }

    public List<Requisition__c > Requisitions {get;set;}
    public string approve {get; set;}

    public CSRF_Challenge(){
        if(Requisitions == null){
            Requisitions= new List<Requisition__c>();
            for(Requisition__c req: [SELECT Approved__c,Castle__c,Description__c,Id,Name,Quantity__c,Resource__c FROM Requisition__c]){
                Requisitions.add(req);
            }
        }
    }

    public void approveReq(){
        approve = ApexPages.currentPage().getParameters().get('approve');
        if(approve!=null){
            For(Requisition__c req : Requisitions){
                if(req.id==approve){
                    req.approved__c = true;
                    update req;
                    approve = null;
                }
            }
        }
    }

    public void approveReqNOCSRF(){
        if(approve!=null){
            For(Requisition__c req : Requisitions){
                if(req.id==approve){
                    req.approved__c = true;
                    update req;
                    approve = null;
                }
            }
        }    
    }


}

All the fields are present in Requisitions object-

However, it is throwing me error all the properties as unknown property e.g. Error: Unknown property 'String.Castle__c'

Please help

0

Your Visualforce page is binding to public String req { get; set; } instead of the var="req". You should not have a public property that matches a var, because things like this will happen. Removing the public String req { get; set; } should be sufficient to compile your code.

  • Thanks sfdcfox.. Yeah it worked.. I understand what are you are trying to say. Basically, visualforce was getting confused while binding to property or the var. This is actually bug in the challenge code then. didn't notice the property there :/ Thanks. – mvk1991 Jun 14 '17 at 10:32
  • @mvk1991 Yeah; if you got this code directly from a trailhead, it's pretty much a 101 crash course on how to not write code. Half of the code isn't even necessary. – sfdcfox Jun 14 '17 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.