function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonathan Wolff 7Jonathan Wolff 7 

Error in Apex class: Illegal conversion from Contact to System.PageReference

Hello, I build a small Visualforce page with an apex class. 
I get the error "Illegal conversion from Contact to System.PageReference" at return obj; .
Could you tell me how I can fix this error?

VF:
 
<apex:page controller="updateJobStatus" action="{!updateRec}" cache="false">
	<apex:form>
		Thank you.
	</apex:form>
</apex:page>

Apex class:
 
public class  updateJobStatus{

	public String recId {get;set;}
	public String isJobCompleted {get;set;}

	public updateJobStatus() {
		recId = ApexPages.currentPage().getParameters().get('recId');
		isJobCompleted = ApexPages.currentPage().getParameters().get('isJobCompleted');
	}
	public PageReference updateRec() {
		
		Contact obj = new Contact();
		obj.Id = recId;
		obj.R_ckantwort__c = isJobCompleted;
		update obj;
        return obj;
       
	}


}

 
mukesh guptamukesh gupta
HI Jonathan,

Please use below code:-
 
public class  updateJobStatus{

	public String recId {get;set;}
	public String isJobCompleted {get;set;}

	public updateJobStatus() {
		recId = ApexPages.currentPage().getParameters().get('recId');
		isJobCompleted = ApexPages.currentPage().getParameters().get('isJobCompleted');
	}
	public void updateRec() {
		
		Contact obj = new Contact();
		obj.Id = recId;
		obj.R_ckantwort__c = isJobCompleted;
		update obj;
      
       
	}


}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh