# ContextService Error: Call to a member function getId() on null

**URL:** https://forum.shopware.com/t/contextservice-error-call-to-a-member-function-getid-on-null/54063
**Category:** Programmierung
**Created:** [13. Juli 2018 um 13:02 UTC](https://forum.shopware.com/t/contextservice-error-call-to-a-member-function-getid-on-null/54063 "2018-07-13T13:02:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Reinelt](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/reinelt/32/7837_2.png) [@Reinelt](https://forum.shopware.com/u/Reinelt)
#### Post date: [13. Juli 2018 um 13:02 UTC](https://forum.shopware.com/t/contextservice-error-call-to-a-member-function-getid-on-null/54063/1 "2018-07-13T13:02:51Z")

</div>

Ich brauche in meiner Klasse den ContextService um an die ShopId zu kommen, nur bekomme ich einen Fehler beim theme cache generieren, der sich mir nicht wirklich erschließt.

Die Klasse/Service der den ContextService braucht habe ich in der services.xml zugewiesen.

**So schaut ein Teil der Translation Klasse aus, der dafür relevant ist.**

```
use Doctrine\DBAL\Connection;
use Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface;
use Shopware_Components_Translation as Translator;

public function __construct(ContextServiceInterface $contextService, Connection $connection)
{
    $this->contextService = $contextService;
    $this->connection = $connection;
    $this->translator = new Translator();
}

private function getTranslation($translationType, $objectId, $string)
{
    $shopId = $this->contextService->getShopContext()->getShop()->getId();
}

```

Die getTranslation rufe ich in einer anderen Klasse aus&nbsp;

```
$this->translation = $this->container->get('mega_danger_notes.bundle.translation');
......
....
.
$this->translation->translateString($satz->getDescription(), 'h', $satz->getId());

```

&nbsp;
