Window.close not Working in page Refernce Apex method - salesforce

I have page reference method in apex controller.
I need to close the current tab .
Here is my code:
public PageReference savePostSurveyAnswer(){
String sitePathPrefix = Site.getPathPrefix();
System.debug('savePostSurveyAnswer method start');
CaseIdentifierIdValue = ApexPages.currentPage().getParameters().get('caseIdentifierId');
ShGl_PostChatSurvey__c postChatSurvey = new ShGl_PostChatSurvey__c();
postChatSurvey.ShGl_SurveyQuestion1__c = question1;
postChatSurvey.ShGl_SurveyQuestion2__c = question2;
postChatSurvey.ShGl_SurveyQuestion3__c = question3;
postChatSurvey.ShGl_SurveyQuestion4__c = question4;
postChatSurvey.ShGl_SurveyResponse1__c = questionAnsSelected1;
postChatSurvey.ShGl_SurveyResponse2__c = questionAnsSelected2;
postChatSurvey.ShGl_SurveyResponse3__c = questionAnsSelected3;
postChatSurvey.ShGl_SurveyResponse4__c = questionAnsSelected4;
postChatSurvey.ShGl_Market_Code__c = 'US'; //new data base model
postChatSurvey.ShGl_UniqueCaseIdentifier__c = CaseIdentifierIdValue;
//postChatSurvey.ShGl_LiveTranscriptChatKey__c = chatKeyIdValue;
//postChatSurvey.ShGl_CaseOfSurvey__c = (Id) LiveChatTranscriptObj.CaseId; //through trigger
Database.SaveResult postSaveResult = Database.insert(postChatSurvey);
return new PageReference('javascript:window.close();');
}
Thanks in advance.
Any help would be appreciated.

When you check the documentation for Window.close() you will find the reason:
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
In short: The browser won't let you. This is not specific to Salesforce or VF. Windows.close() would anyway not close a tab, but the whole browser window.
If you are looking to close a console tab, this question/answer might provide what you are looking for.

Related

Can not locate menu with link after hovering on link for coded UI

Currently I'm having issues returning either inner text or even links from a tool tip menu that displays after i hover over a link. Using dev tool I see that this link and the hover menu that appears in a Div labeled alphabetTooltip. Can anyone let me know if i'm going in the correct direction with this.
public void get_All_Carousel_Cards_ofAlphabet() {
//Mouse.Click(CarouselLinks);
Mouse.Hover(CarouselLinks);
HtmlDiv tooltipdiv = new HtmlDiv();
tooltipdiv.SearchProperties[HtmlDiv.PropertyNames.Class] = "alphabetTooltip";
HtmlControl controls = new HtmlControl();
controls.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "HtmlHyperlink");
UITestControlCollection collection = controls.FindMatchingControls();
foreach (UITestControl links in collection)
{
//cast the item to html hyperlink typ
HtmlHyperlink mylinks = (HtmlHyperlink)links;
//get the innertext from the link, which inturn returns the link value itself
carousel_innerText = mylinks.InnerText;
}
}
Try adding the tooltip as the parent for the hyperlink search as follows:
HtmlDiv tooltipdiv = new HtmlDiv();
tooltipdiv.SearchProperties[HtmlDiv.PropertyNames.Class] = "alphabetTooltip";
HtmlControl controls = new HtmlControl(tooltipdiv);

Sitecore Glass mapper GetItem<TypeName>(guid) always return null

I saw a related question:
Sitecore Glass Mapper always null
But unfortunately it does not give a solution for my case.
Here goes a code snippet:
var db = Factory.GetDatabase("master");
var context = new SitecoreContext();
// the ID of Needed item
var g = new Guid("{F21C04FE-8826-41AB-9F3C-F7BDF5B35C76}");
// just to test if it's possible to fetch item using db.GetItem
var i = db.GetItem(new ID(g), Language.Current, Sitecore.Data.Version.Latest);
// Grab item
var t = context.GetItem<Article>(g);
In the code above:
i is not null
t is null
Article is the simple class like:
[SitecoreType(TemplateId = "{4C4EC1DA-EB77-4001-A7F9-E4C2F61A9BE9}")]
public class Article
{
[SitecoreField(FieldName = "Title")]
public string Title { get; set; }
}
There are only one language installed in Sitecore - en, it has been specified in the web.config in the items as well.
Also I have added GlassMapperSc.Start(); to Application_Start in the Global.asax.cs and added my assembly to the list of included assemblies via var attributes = new AttributeConfigurationLoader(new[] { "Assembly.Name" }); and I succeeded to find my class in the SitecoreContext mappings.
It does not looks like a language issue, as stated in the link provided in the very beginning. And I'm struggling with it already for a pretty long time, but no luck...
Thank You!
I just noticed that you are using master db for the Sitecore DB and SitecoreContext for Glass.
The SitecoreContext class will use the database that is defined by the Sitecore.Context.Database property at runtime. This probably means that it is using the web database.
Can you check that you have published the item to the web database or instead using:
var context = new SitecoreService("master");

Prestashop api - How to get the current cart contents

I'm new to Prestashop, I cant find examples anywhere of how to get the current cart contents. I can get a list of all carts, but how do I get the current users cart?
it is easy and simple. I am considering you are using PS 1.5.x
In controllers other than cart controller
$cart = new Cart($this->context->cookie->id_cart);
or in an class
$context = new Context();
$cart = new Cart($context->cookie->id_cart);
Now the $cart is an object, and it has all the current cart data.
You can also get the cart products by calling getProducts like below
$cartProducts = $cart->getProducts();
Hope this will help.
Please note that code is not tested and is just a sample code for your idea.
Thank you
For PS 1.4.X you can get using getProducts()
$product_array = $this->getProducts();
print_r($product_array);
Example :
public function getSubTotal() {
$product_array = $this->getProducts();
foreach($product_array as $product_item) {
$sub_total += $product_item['price'] * $product_item['cart_quantity'];
}
return $sub_total;
}

Workflows Fail on Start when adding an item to a list programmatically

I have a custom built web service that is built to simply add items into a list in SharePoint Foundation 2010. I have workflow attached to the list but when I create an item using my web service (which references the SharePoint Object Model) workflows 'Fail on Start'. If I add an item to the list directly within SharePoint the workflows start as required with no problems. I have tried the following so far (including all variations of using them together) but non of these fix the issue:
Using SPSecurity.RunWithElevatedPrivilages to run my code
Impersonating a different user to the Administrator and System Account to create the item as
Running my application pool as the same user as my site's application pool
Running my application pool as a different account to my site's application pool user
The web service is not failing and it is creating the items, just the workflows are not running... can anyone help me with this please?
The code I am using to create the list item is as follows:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite oTempSite = new SPSite(SharePointSite);
SPUser oUserImpersonate = oTempSite.OpenWeb().EnsureUser(UserToEntryAs);
SPSite oSite = new SPSite(SharePointSite, oUserImpersonate.UserToken);
SPWeb oWeb = oSite.OpenWeb();
try
{
oSite.AllowUnsafeUpdates = true;
oWeb.AllowUnsafeUpdates = true;
SPList oList = oWeb.Lists["Sample Log"];
SPListItem oNewItem = oList.Items.Add();
oNewItem["Customer"] = intCustomerID;
oNewItem["Cust. Contact Name"] = strCustomerContactName;
oNewItem["Contact Email"] = strCustomerContactEmail;
oNewItem["Sample Number"] = strSampleNumber;
oNewItem["Notes"] = strNotes;
oNewItem["Application"] = strSampleApplication;
oNewItem["Despatch Method"] = strDespatchMethod;
oNewItem["Cost"] = dblCost;
oNewItem["Sample 1"] = intSampleProductID;
oNewItem["Weight 1"] = strSampleWeight;
oNewItem["Batch No. 1"] = strSampleBatch;
//Handle Account Manager(s):
SPFieldUserValueCollection usrAccountManagers = new SPFieldUserValueCollection();
foreach (string strAcctMrg in AccountManagers.Split(';'))
{
SPUser oUser = oWeb.EnsureUser(strAcctMrg);
usrAccountManagers.Add(new SPFieldUserValue(oWeb, oUser.ID, oUser.LoginName));
}
oNewItem["Account Manager"] = usrAccountManagers;
oNewItem["Content Type"] = "Ingredient Sample"; //Set the content type to be 'Ingredient Sample'
oNewItem["Ingredient Sample Status"] = "Awaiting Result"; //Set the status to default to 'Awaiting Result'
oNewItem.Update();
Thanks in advance...
After researching the ULS log errors I found the issue was with my web.config file on my Web Service that needed the Authorized types declaring for the workflows to be able to run on the item I had created.
I used this post to help me resolve it: http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/71d23c0e-24c5-4d61-8d62-265c374ac81c/

Form won't display. . . Dooh!

I could use a little help. I got this program to work right then I found out I had to use the MVC design. It seems pretty simple but, my little toy program won't display my forms. HELP!! See the below snipets:
PART OF MIDLET
public MileageMidlet()
{
// First get a blank user form
form = new Form("Bradford Gas Mileage Calculator");
startPage = new StartPageView();
inputScreen = new InputScreen();
calculateMileage = new CalculateMileage();
startCmd = new Command ("Start",Command.SCREEN,5);
clearCmd = new Command ("Clear",Command.SCREEN,1);
enterCmd = new Command ("Enter",Command.SCREEN,1);
exitCmd = new Command("Exit", Command.EXIT, 1);
// Set up event handlers to process user commands
form.setCommandListener(this);
}
public void startApp() {
startPage.createView(form);
form.addCommand(startCmd);
form.addCommand(exitCmd);
// Display initial form
Display.getDisplay(this).setCurrent(form);
}
START PAGE VIEW CLASS
import javax.microedition.lcdui.*;
public class StartPageView
{
StringItem strgItm, strgItm2;
private Command startCmd, exitCmd;
public StartPageView()
{
}
public void createView(Form form)
{
// First get a blank user form
form.deleteAll();
form = new Form("Bradford Gas Mileage Calculator");
strgItm = new StringItem ("","Welcome to the Bradford Mobile Gas Mileage Calculator!");
strgItm2 = new StringItem ("","To obtain you gas mileage please click the start button.");
form.append(strgItm);
form.append(strgItm2);
}
I got nothing! Really literally a blue screen.
}
The issue has nothing to do with MIDP or J2ME. The problem is of the semantics of how arguments are passed to methods.
It;s important to remember that arguments to method are passed by value in Java. The consequence is that when an object that is passed to a method, a copy of that reference is passed. Any changes to the reference of the object in the method does not have any affect outside of it.
Please see this article for more information.
So in your code,
form.deleteAll();
form = new Form("Bradford Gas Mileage Calculator");
Comment the above two lines. Everything should be fine.

Resources