Error: Compile Error: Illegal conversion from String to System.PageReference



Controller:

public PageReference getURL(){
String  url='www.google.com';
//your Logic
return url;
When you save it would throw and error

Error: Compile Error: Illegal conversion from String to System.PageReference
you were supposed to return a PageRefernce(A PageReference is a reference to an instantiation of a page) not Just simple String

Solution:
Create an instantiation of a page and return the instance.


public PageReference getURL(){
String  url='www.google.com';
//your Logic
PageReference pageRef = new PageReference(url);
return pageRef;
}

P.S: Comment Below for any Clarification or help!!
Happy working!! :) :) 

Comments

Post a Comment

Popular posts from this blog

Embed Special Characters in VF Page

Some Common Errors in the Visual flow