Q:

Get Quote from Order Success Observer

I tried to get quote from success order observer like this:

app/code/Vendor/Module/etc/frontend/events.xml

<event name="checkout_onepage_controller_success_action">
    <observer instance="Vendor\Salesman\Observer\Customer\OrderSuccess" name="lime_salesman_observer_onepage_success_action" />
    </event>

app/code/Vendor/Module/Observer/Customer/OrderSuccess.php

public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
      $order = $observer->getEvent()->getOrder();
      $quote = $this->quoteFactory->create()->load($order->getQuoteId());
}

but i got an error like this:

PHP Fatal error:  Uncaught Error: Call to a member function
  getQuoteId() on null

A:

By using this observer you can get only order_ids
if you want to get quote_id you need to load order object.
load order using order id after then you can get quote_id by using $order->getQuoteId();

1.etc/event.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
      <event name="checkout_onepage_controller_success_action">
            <observer name="namespace_modulename_observer_getquote" instance="Namespace\ModuleName\Observer\Getquote" />
      </event>
</config>

2.Observer\Getquote.php
<?php
namespace Namespace\ModuleName\Observer;

class Getquote implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $orderId = $observer->getEvent()->getOrderIds();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId[0]);
        echo $order->getQuoteId(); exit;
    }
}

