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
pradeep m 27pradeep m 27 

Compile Error: No such column 'color__c' on entity 'Product2'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. at line 9 column 3

trigger oppLineTrigger on OpportunityLineItem (before insert) {
Set<Id> pbeIds = new Set<Id>();
  for (OpportunityLineItem oli : Trigger.new)
  pbeIds.add(oli.pricebookentryid);
Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>(
  [select Product2.color__c from PricebookEntry where id in :pbeIds]);
  for (OpportunityLineItem oli : Trigger.new)
  oli.color__c = entries.get(oli.pricebookEntryId).product2.color__c;
}
NagaNaga (Salesforce Developers) 
Hi Pradeep,

I think it might be a permission issue, please check if the concerned user has access to fields in this customobject "color".

Please check the link below

http://salesforce.stackexchange.com/questions/50824/invalid-field-username-on-user-soql-query

Best Regards
Naga Kiran
Amit Chaudhary 8Amit Chaudhary 8
Please try below code :-
trigger oppLineTrigger on OpportunityLineItem (before insert) 
{
	Set<Id> pbeIds = new Set<Id>();
	for (OpportunityLineItem oli : Trigger.new)
	{
		pbeIds.add(oli.pricebookentryid);
	}
	
	Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>([select Id,Product2.color__c from PricebookEntry where id in :pbeIds]);
	for (OpportunityLineItem oli : Trigger.new)
	{
		if(entries.containsKey(oli.pricebookEntryId))
		{
			oli.color__c = entries.get(oli.pricebookEntryId).product2.color__c;
		}	
	}
}

NOTE:- Please follow below Step to fix this issue
1) Please check API Name of field Color on Product2 object and "OpportunityLineItem
2) Please provide Field level access of both field to all user.

Please let us know if this will help you

Thanks
Amit Chaudhary