<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How to "ADDING, UPDATING, AND DELETING ASSETS" in 7.1?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110962666" />
  <subtitle>How to "ADDING, UPDATING, AND DELETING ASSETS" in 7.1?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110962666</id>
  <updated>2026-04-05T09:36:53Z</updated>
  <dc:date>2026-04-05T09:36:53Z</dc:date>
  <entry>
    <title>RE: How to "ADDING, UPDATING, AND DELETING ASSETS" in 7.1?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110972223" />
    <author>
      <name>Mirto Silvio Busico</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110972223</id>
    <updated>2018-09-18T11:23:18Z</updated>
    <published>2018-09-18T11:23:18Z</published>
    <summary type="html">&lt;p&gt;Well, I'm not sure to do it correctly.&lt;/p&gt;
&lt;p&gt;Now this code in &lt;strong&gt;FooLocalServiceImpl.java&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;
    @Indexable(type = IndexableType.DELETE)
    @Override
    public Foo deleteFoo(long fooId, ServiceContext serviceContext) throws PortalException {
        Foo foo = fooPersistence.remove(fooId);
        
        assetEntryLocalService.deleteEntry(
            Foo.class.getName(), foo.getFooId());

        Indexer&amp;lt;Foo&amp;gt; indexer = IndexerRegistryUtil.nullSafeGetIndexer(Foo.class);
        indexer.delete(foo);

        return foo;
    }
&lt;/pre&gt;
&lt;p&gt;doesn't generate a compile error.&lt;/p&gt;
&lt;p&gt;Sadly I cannot test it because the call in &lt;strong&gt;MsbOnePortlet.java&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;
    protected void deleteFoo(ActionRequest actionRequest) throws Exception {
        long fooId = ParamUtil.getLong(actionRequest, &amp;quot;fooId&amp;quot;);

        ServiceContext serviceContext = ServiceContextFactory.getInstance(Foo.class.getName(), actionRequest);

        &lt;strong&gt;getFooLocalService().deleteFoo(fooId, serviceContext);&lt;/strong&gt;
    }
&lt;/pre&gt;
&lt;p&gt;to &lt;strong&gt;deleteFoo&lt;/strong&gt; generates a runtime error &lt;/p&gt;
&lt;div class="portlet-msg-error"&gt;Servlet execution threw an exception&lt;/div&gt;
&lt;p&gt;before calling the foo local service.&lt;/p&gt;
&lt;p&gt;I'm still debugging/investigating.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Mirto Silvio Busico</dc:creator>
    <dc:date>2018-09-18T11:23:18Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to "ADDING, UPDATING, AND DELETING ASSETS" in 7.1?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110964750" />
    <author>
      <name>Jorge Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110964750</id>
    <updated>2018-09-17T10:58:22Z</updated>
    <published>2018-09-17T10:58:22Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi Mirto,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;About example of &lt;a href="https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/adding-updating-and-deleting-assets"&gt;https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/adding-updating-and-deleting-assets&lt;/a&gt;
  page, the object "assetEntry" is the object you are deleting
  of your custom entry.&lt;/p&gt;
&lt;p&gt;It is confusing because it seems it is referring to AssetEntry
  object, but it is referring to "foo"&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Perhaps it is more easy to understand the code if&amp;nbsp; you replace
  "assetEntry" variable with "foo" variable:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;assetEntryLocalService.deleteEntry(
    ENTITY.class.getName(), foo.getEntityId());

Indexer&amp;amp;lt;ENTITY&amp;amp;gt; indexer = IndexerRegistryUtil.nullSafeGetIndexer(ENTITY.class);
indexer.delete(foo);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
  &lt;strong&gt;Note:&lt;/strong&gt;
  &lt;code&gt;foo.getEntityId())&lt;/code&gt; == similar behavior than ==&amp;gt; &lt;code&gt;foo.getPrimaryKey())&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Jorge Diaz</dc:creator>
    <dc:date>2018-09-17T10:58:22Z</dc:date>
  </entry>
  <entry>
    <title>How to "ADDING, UPDATING, AND DELETING ASSETS" in 7.1?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110962665" />
    <author>
      <name>Mirto Silvio Busico</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110962665</id>
    <updated>2018-09-17T08:31:42Z</updated>
    <published>2018-09-17T08:31:42Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I'm trying to create an MVC potlet to manage a Foo entity integrated
  with the asset framework.&lt;/p&gt;
&lt;p&gt;I'm stuck with the 7.1 documentation at:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
  &lt;a href="https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/adding-updating-and-deleting-assets"&gt;https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/adding-updating-and-deleting-assets&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Trying to write the delete code I see that in the
  &lt;strong&gt;FooLocalServiceBaseImpl.java&lt;/strong&gt; I have&lt;/p&gt;
&lt;pre&gt;
    @Indexable(type = IndexableType.DELETE)
    @Override
    public Foo deleteFoo(Foo foo) {
        return fooPersistence.remove(foo);
    }
&lt;/pre&gt;
&lt;p&gt;Copied this code in &lt;strong&gt;FooLocalServiceImpl.java&lt;/strong&gt;
  everything works as expected.&lt;/p&gt;
&lt;p&gt;Then I tried to add the code to delete the asset entry data taken
  from the documentation:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;assetEntryLocalService.deleteEntry(
    ENTITY.class.getName(), assetEntry.getEntityId());

Indexer&amp;amp;lt;ENTITY&amp;amp;gt; indexer = IndexerRegistryUtil.nullSafeGetIndexer(ENTITY.class);
indexer.delete(assetEntry);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Changing ENTITY with Foo my code is now:&lt;/p&gt;
&lt;pre&gt;
    @Indexable(type = IndexableType.DELETE)
    @Override
    public Foo deleteFoo(Foo foo) {
        fooPersistence.remove(foo);

        assetEntryLocalService.deleteEntry(Foo.class.getName(), assetEntry.getEntryId());
        Indexer&amp;lt;Foo&amp;gt; indexer = IndexerRegistryUtil.nullSafeGetIndexer(Foo.class);
        indexer.delete(assetEntry);    
        return foo;
    }
&lt;/pre&gt;
&lt;p&gt;This obviously gives the error that assetEntry is not defined. So I
  tried to add it and the code is now:&lt;/p&gt;
&lt;pre&gt;
    @Indexable(type = IndexableType.DELETE)
    @Override
    public Foo deleteFoo(Foo foo) {
        fooPersistence.remove(foo);
        
       &lt;strong&gt; AssetEntry assetEntry = assetEntryLocalService.fetchAssetEntry(foo.getPrimaryKey());&lt;/strong&gt;
        
        assetEntryLocalService.deleteEntry(Foo.class.getName(), assetEntry.getEntryId());
        Indexer&amp;lt;Foo&amp;gt; indexer = IndexerRegistryUtil.nullSafeGetIndexer(Foo.class);
        indexer.delete(assetEntry);    
        return foo;
    }
&lt;/pre&gt;
&lt;p&gt;But this on the&amp;nbsp;&lt;code&gt;indexer.delete(assetEntry);&lt;/code&gt; line gives
  the error:&lt;/p&gt;
&lt;pre&gt;
&lt;strong&gt;error: incompatible types: AssetEntry cannot be converted to Foo
&lt;/strong&gt;&lt;/pre&gt;
&lt;p&gt;What is the correct code to delete an assetEntry?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Mirto Silvio Busico</dc:creator>
    <dc:date>2018-09-17T08:31:42Z</dc:date>
  </entry>
</feed>
