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
AtulBharmalAtulBharmal 

Close the VisaulForce Pop - UP windows In apex controller

Hello,

 

          I have a custom button on a object which open a visual force page pop-up.

Can some body please help me or let me know. Is there any way I can close the window thorough the controller itself.

 

As I Do have validation in which if the data inserted is correct. The windows will close and save the data. And if the data is incorrect the class return a error message. If I write a Ajax close whenever the the call come back with message it close the window without showing the message.

 

Please help me and let me know if we can close the window in apex class (Controller) ???

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

You should use Ajax for this.

Why dont you use oncomplete in the VF tag you are invoking the controller.

In oncomplete, invoke the javascript function that will close the window based on the result you get from Controller.

All Answers

Imran MohammedImran Mohammed

You should use Ajax for this.

Why dont you use oncomplete in the VF tag you are invoking the controller.

In oncomplete, invoke the javascript function that will close the window based on the result you get from Controller.

This was selected as the best answer
AtulBharmalAtulBharmal

Thanks for your reply.

 

 

I am done with the problem i have used ajax and onstop i have called a javascript..

 

and also tried with what you said worked like a charm

 

thanks.

PeterWagenerPeterWagener

If you want a cheap way to do this without using the Ajax features, you can always just return a javascript function as the PageReference from the controller:

 

    return new PageReference('javascript:window.close()');

 

Might seem silly, but it's effective!

Imran MohammedImran Mohammed

Thanks Peter for sharing useful info with us.

MohandaasMohandaas

Peter, I am getting the below error.

 

java.lang.IllegalArgumentException: Illegal view ID javascript:window.close(). The ID must begin with / 

turbo2ohturbo2oh

I got the same error.

ztrankztrank
return new PageReference('javascript:window.self.close()');
Yasha Reddy 17Yasha Reddy 17
Thank you. This helped. How do i refresh the parent window at the same time?