You need to sign in to do that
Don't have an account?

how to fix below error
Hi Everyone,
I am getting "CSRF with VF Call" checkmarx error from below code. So i have added get method to apex class as shown below. But I am not getting how to call get method in test class.
Please help me to include get method in test class.
Thanks in advance!
Below code is the test class that i have written but not getting how to include get method in it.
"i just tried by calling it as Classname.methodname" getting error.
I am getting "CSRF with VF Call" checkmarx error from below code. So i have added get method to apex class as shown below. But I am not getting how to call get method in test class.
Please help me to include get method in test class.
Thanks in advance!
Apex class: public class xyz { public abc objabc{get;set;} public Boolean sendEmail {get; set;} public Task objtask{get;set;} public boolean isChecked{get;set;} public xyz() { String objabcId = ApexPages.currentPage().getParameters().get('id'); objabc = new abc(); if(objabcId !=null && objabcId !=''){ objabc = [Select id,OwnerId,name from abc where id=:ApexPages.currentPage().getParameters().get('id')]; } if(objabc.id!=null){ sendEmail = true; objtask= new task(); objtask.whatid=objabc.id; objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id; objtask.status = 'Completed'; objtask.type = 'Assigned'; objtask.OwnerID = UserInfo.getUserId(); objtask.Subject='Assignment'; } } public abc getabc(){ return objabc; } public pagereference save() { try { if(objtask.subject!=null){ insert objtask; update objabc; if(sendEmail){ Database.DMLOptions dlo = new Database.DMLOptions(); dlo.EmailHeader.triggerUserEmail = true; database.update(objabc,dlo); } }else{ Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!')); return null; } string abcobjurl = objabc.id; abcobjurl = abcobjurl.substring(0,3); PageReference orderPage = new PageReference('/' + abcobjurl); return orderPage; } catch (Exception e) { system.debug('---inside Exception---'+e.getMessage()); system.debug('---inside Exception Line---'+e.getLineNumber()); Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage())); return null; } } }
Below code is the test class that i have written but not getting how to include get method in it.
"i just tried by calling it as Classname.methodname" getting error.
Test class: @IsTest Public class TestShareFilesWithCommunityUsers { @IsTest Public static void testmethod1(){ Test.startTest(); abc oAbc =new abc (Name='Demo');//Fill All Required Fields insert oAbc ; ApexPages.currentPage().getParameters().put('id',oAbc .id); xyz abc= new xyz(); abc.save(); abc.objabc = oAbc; abc.sendEmail = true; Test.stopTest(); } }
If this helps, Please mark it as best answer.
Thanks!!
Getting errors as below:
1) In test class for below lines getting error as "line 1: Final members can only be assigned in their declaration, init blocks, or constructors: objabc"
and "line 2: Static method cannot be referenced from a non static context: abc xyz.getabc()"
2) In apex code getting error as "line 2: Variable does not exist: objabc" Please help me to resolve this.
Thanks!
Static method cannot be referenced from a non static context: abc xyz.getabc()" to fix error, try with below.
//Classname.methodname
xyz.save();
You need to declare the variable for objabc
If still facing an error, then send me the VF page code also.
Thanks!!
1) If i use classname.methodname getting error "Non static method cannot be referenced from a static context: System.PageReference abc.save()"
2) where to declare the variable and how
Thanks!!