function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VarunCVarunC 

Before trigger on ContentVersion not updating TagCsv field value

for (ContentVersion cv : trigger.new)
{
	if (cv.Contact__c != null && cv.Hold__c == true)
	{
		cv.TagCsv = 'Hold';
	}
	system.debug('@@ cv.TagCsv : ' + cv.TagCsv);
}

This code has been put on ContentVersion, Before Update trigger. And this debug line: system.debug('@@ cv.TagCsv : ' + cv.TagCsv);, also shows that TagCsv field has been put value into it successfully, but when I go into the Content record, the Tags field is coming in Empty.

 

Is this some kind of Bug ?

RustanRustan

That's because you haven't told the system to save it yet.

 

try this

 

list<ContentVersion> saveCV = new list<ContentVersion>();

 

for (ContentVersion cv : trigger.new)
{
if (cv.Contact__c != null && cv.Hold__c == true)
{
cv.TagCsv = 'Hold';

saveCV.add(cv);
}
system.debug('@@ cv.TagCsv : ' + cv.TagCsv);
}

 

update saveCV;

VarunCVarunC

Hi Rustam, thnx for the reply.

 

But the issue is not with calling of save here.

 

My trigger is activated on "Before Update", so I don't need to call Save again on it to save values. I can update field values and database commits are automatically called in before triggers.

HariDineshHariDinesh

Hi,

Yes, You don’t need to write update statement’s in before triggers.

 

Seems there is no problem with your code.

Try to put more debug statements in you trigger and observe the Debug logs also clearly, is there any exception like that?

And one more is include TRY and Catch Blocks for the code and put debugs in catch block.

If still you are not able to find paste you complete code.

VarunCVarunC
trigger ContentVersionTrigger on ContentVersion (before insert, before update) 
{
	if (trigger.isBefore && (trigger.isUpdate || trigger.isInsert))
	{
		for (ContentVersion cv : trigger.new)
		{
			system.debug('@@ Tag Before: '+cv.TagCsv);
			cv.TagCsv = 'Hold';
			system.debug('@@ Tag After: '+cv.TagCsv);
		}
	}
}

 The above should work, but it isn't. I don't find any flaw in it but I'm open to suggestions to sort this out.

 

Ankita GAnkita G

Hello, I am also getting the same issue. Were you able to get any resolution for this one ??

 

Thanks in Advance

hphp
I'm having the same challenge. Is it do with following?

Values for the TagCsv and VersionData fields are only available in triggers if the request to create or update ContentVersion records originates from the API.

(Source: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_ignoring_operations.htm)