How can I get entry id in field I create a new filed type and attached it to entries. Now I need to get the entry id which the field is attached to. 

I tried $this-&gt;element in my field class, but got an error said that I'm calling an unknown property.

Any way to do that please?
It may depend on where in the request you need to access the element.

If you need to access the element in a Field class on your Entry Edit page, the getInputHtml method may be useful:

public function getInputHtml($value, ElementInterface $element = null): string
{
    // $element stuff

    return Craft::$app-&gt;getView()-&gt;renderTemplate('my-plugin/field',
    [
        'field' =&gt; $this,

        // make the Element available in your field's input template
        'element' =&gt; $element
    ]);
}


If you need to access the element in a Field class after the Element is saved there is the afterSaveElement method:

public function afterElementSave(ElementInterface $element, bool $isNew)
{
    parent::afterElementSave($element, $isNew);

    // $element stuff
}


Note: The Entry ID may not exist while a new entry is being created. Accessing the Element via the afterElementSave ensures that the Entry has been saved and has an ID.