You need to sign in to do that
Don't have an account?

Need help with trigger that copies from opportunitylineitems to a generic field.
I have a rich text field on the opportunity that I need to populate with various peices of data on the opportunity. I have two main issues:
1. I am able to do this, but with only a single data type at a time. I can not seem to figure out how to combine all three lists into a single list. Here is what I have so far.
2. My \n is not making the next line item go on to a new line down.
trigger OpportunityProuctCopytoHiddenField on Opportunity (before insert, before update) {
for(Opportunity t:trigger.new)
{
List<String> NewList= new List<String>();
List<Decimal> NewList2= new List<Decimal>();
List<Datetime> NewList3= new List<Datetime>();
if (t.HasOpportunityLineItem == true)
{
for(OpportunityLineItem OpLine: [SELECT CreatedBy.Name, Quantity, TotalPrice, LastModifiedDate, PriceBookEntry.Name, UnitPrice, ID FROM OpportunityLineItem WHERE OpportunityId =:t.Id] )
{
NewList.add(OpLine.PriceBookEntry.Name);
NewList.add(' has been authorized by ');
NewList2.add(OpLine.Quantity);
NewList.add(OpLine.CreatedBy.Name);
NewList.add('and the transation has been logged into the record id: ');
NewList.add(OpLine.ID);
NewList.add(' on');
NewList3.add(OpLine.LastModifiedDate);
}
for(String c : NewList){
t.Hidden_Products__c = t.Hidden_Products__c + c + '\n';
}
}
}
}
And i am pretty sure what I am missing is somewhere around:
for(String c : NewList){
t.Hidden_Products__c = t.Hidden_Products__c + c + '\n';
Hi,
Try Using the below code.. I have modified it... I think you were missing the escape Character..
t.Hidden_Products__c = t.Hidden_Products__c + c + ''\'n';
Thanks,
KR
Thanks for the reply, but that did not work, upon saving the trigger I recevied the following error:
Ok, so I found I can reslove on of the problems with by replacing:
t.Hidden_Products__c = t.Hidden_Products__c + c + '\n';
with
t.Hidden_Products__c = t.Hidden_Products__c + c + '<br>';
Now only one major issue remain, how do I concatenate NewList, NewList2 and NewList3 into a single string that will output to my hidden_field__C ?
Also, just curious, how do I clear the old data out of the field prior to inserting this new string?
Thanks