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
msimondsmsimonds 

Help Trigger failes to update opportunitylineitem

I am trying to get this trigger to update a new, test field (TEXT FIELD, 18 bytes) with the ID of the Opportunity Line Item and the error that I am receiving is Id not specified in the update call.

 

 

 

 

trigger New_Feed_Update on OpportunityLineItem (after update) 
{
	//setup a feedpost array
	List<FeedPost> posts = new List<FeedPost>();
	
	//Create a new, empty list to add the Socket ID's to update
	List<OpportunityLineItem> oppGetIds = new List<OpportunityLineItem>();
	//mike_test__c
	for(OpportunityLineItem oppids : Trigger.new)
	{
		OpportunityLineItem Opp = new OpportunityLineItem();
		Opp.will_test__c = oppids.id;
		OppGetIds.add(Opp);
	}
    Database.update(OppGetIds);



}

 

 

I thought that the ID was already identified in the update call

 

Can someone please help me fix this trigger

Best Answer chosen by Admin (Salesforce Developers) 
msimondsmsimonds

Srini

 

Actually I messed around with your  code a little and  changed one line

 

 

trigger New_Feed_Update on OpportunityLineItem (before update)
{

for (OpportunityLineItem oli : Trigger.new)
{
oli.will_test__c = oli.id;
}

}

 and one thing that I did not know, but now do, is that before insert or before update will update the record

 

 

Thanks for your help and guidance

 

~Mike

 

All Answers

hisrinuhisrinu
trigger New_Feed_Update on OpportunityLineItem (before update){
for(OpportunityLineItem oppids : Trigger.new)
Opp.will_test__c = oppids.Id;
}
msimondsmsimonds

Srini,

 

I applied your chages and tried you trigger and it does not work, thanks for trying though, Appreciate it

 

I changed my trigger to match your code  to before update and ran it as is. DId not update anything

 

 

 

trigger New_Feed_Update on OpportunityLineItem (before update) 
{
	
	//Create a new, empty list to add the Socket ID's to update
	List<OpportunityLineItem> oppGetIds = new List<OpportunityLineItem>();
	
	for(OpportunityLineItem oppids : Trigger.new)
	{
		OpportunityLineItem Opp = new OpportunityLineItem();
		Opp.will_test__c = oppids.id;
		oppGetIds.add(Opp);
	}
    update oppGetIds;
}

 

 

also if I run your code as you posted it, it does not perform anything

 

Do you mind taking a look at my newer code above and see if you can guide me through it

 

~Mike

msimondsmsimonds

Srini

 

Actually I messed around with your  code a little and  changed one line

 

 

trigger New_Feed_Update on OpportunityLineItem (before update)
{

for (OpportunityLineItem oli : Trigger.new)
{
oli.will_test__c = oli.id;
}

}

 and one thing that I did not know, but now do, is that before insert or before update will update the record

 

 

Thanks for your help and guidance

 

~Mike

 

This was selected as the best answer