+ Start a Discussion
Jerry ClifftJerry Clifft 

Help with visual force button extension

So, it has been a while and can't seem to remeber quite who to do this. I am making a custom Visual Force button for the case object that when pushed, changes the status of the case.

Here is my VF:
<apex:page standardController="Case" extensions="CaseRecallButton">
    <apex:form >
        <apex:commandButton value="Com - Recall Case" action="{!ReCallCase}" />
    </apex:form>
</apex:page>


Here is my extension:
public with sharing class CaseRecallButton {

Case CA;

    public CaseRecallButton(ApexPages.StandardController controller) {
        this.CA = (Case)Controller.getRecord();
   
    }
        public PageReference ReCallCase(){
        CA.Status='New RECALL';
        Update CA; }
}

And here is my error message:
Error: CaseRecallButton Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 11 column 9

Thanks in advance for the help :)
Best Answer chosen by Jerry Clifft
CJWilderCJWilder
Hi Jerry,

This might work for you.

Create a VF page that's only role is to call a method on a class that sets the status, owner then redirects back to the page your on. Then you can create the comman button to cal this VF page.

<apex:page standardController="Case" extensions="Recall" action="{!ReCallit}"  >

</apex:page>
Extensions Class
public with sharing class Recall {
	
	String CaseId = '';
   
    public Recall(ApexPages.StandardController controller){
        CaseId = ApexPages.currentPage().getParameters().get('id');
    }
	
	
	public Pagereference ReCallIt() {
		Test__c ThisCase = [Select OwnerID, Status from Case where ID = :CaseID];
		ThisCase.status__c = 'New RECALL+';
		ThisCase.OwnerID = UserInfo.getUserId();
                update ThisCase;
                return  new Pagereference('/'+CaseID);
		
	}
	

}



All Answers

CJWilderCJWilder
Hi Jerry,

This should work for you.

public with sharing class CaseRecallButton {
    private final ApexPages.StandardController c;
   
    public testpage(ApexPages.StandardController c){
        this.c = c;
    }

    public PageReference ReCallCase(){

	Case ThisCase = [Select  Status from Case where ID = :c.getId()];
        ThisCase.Status = 'New RECALL';
        update ThisCase;
        return null;

    }
}


Jerry ClifftJerry Clifft
Thanks.

So this mostly works, here is the weird thing, I created a custom button, Content Source / Visual Force page and selected open in same window, I then added this button to my page layout. But when I click the button, the page reloads, the case is gone and all that is on the screen is the button. The case record was not updated. Now, if push the button on the page that loaded after I pushed the button the first time, the case does in fact update, but the page never reloads to show the case, just the empty page with the button is all that appears still.

Any suggestions?
CJWilderCJWilder
Hi Jerry,

Not sure what your trying todo... Kind of reading between the lines it sounds like each time you create a new Case there are conditions when you wan to set the status to 'New Recall'. If that is true you may want to go with a Trigger.

If that's not the case. Tell me more about the cenario that your working on and I'll try to help.

Thanks,
Jerry ClifftJerry Clifft
Sorry, I should have clarified. Scenario:

1. A partner of ours, via Salesforce Communities, creates a Case to request whatever action which routes to our OPS group.
2. The partner decides, before the Case is completed, to cancel / recall the Case.
3. The partner pushes the "Recall Case" button and the case’s status changes from X to “Recalled” owner changes from Y to the name of the person who pushed the button.

I figure, if we get this to the point where the status updates, I can figure out how to change the owner myself.

In the past, with Salesforce’s PRM Portal, I was able to use this to do this function:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.OwnerId = '{!User.Id}';
caseObj.Status = 'Request Recalled';
var result = sforce.connection.update([caseObj]);

if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

But now that we are migrating to Salesforce Communities, and we are using the tabbed version of Communities, the /SOAP/AJAX/ scripts are not available. Which is why I am trying to do this with Visual force and apex/extension.
CJWilderCJWilder
Hi Jerry,

This might work for you.

Create a VF page that's only role is to call a method on a class that sets the status, owner then redirects back to the page your on. Then you can create the comman button to cal this VF page.

<apex:page standardController="Case" extensions="Recall" action="{!ReCallit}"  >

</apex:page>
Extensions Class
public with sharing class Recall {
	
	String CaseId = '';
   
    public Recall(ApexPages.StandardController controller){
        CaseId = ApexPages.currentPage().getParameters().get('id');
    }
	
	
	public Pagereference ReCallIt() {
		Test__c ThisCase = [Select OwnerID, Status from Case where ID = :CaseID];
		ThisCase.status__c = 'New RECALL+';
		ThisCase.OwnerID = UserInfo.getUserId();
                update ThisCase;
                return  new Pagereference('/'+CaseID);
		
	}
	

}



This was selected as the best answer
Jerry ClifftJerry Clifft
Thank you CJWilder, you are a gentleman and genius. This code works perfectly. It will be used in our new SF Community site to allow our partners to recall cases and I will also use it as template to update the other buttons currently in PRM Portal written using soap/ajax/JavaScript so those functions will also be available in our community site.

Thanks again!