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
Nick WhiteNick White 

Invalid bind expression type of Schema.SObjectField for column of type String

Help :-)

I wish to update field PN_Link__c in Object Quotation_Detail__c, (which is a Lookup Field to Object Product2).
Reason, when I upload Quotation Data into Salesforce, I want this trigger to fill the Lookup Field PN_Link__c with the Part Number that is uploaded, so that it creates a relationship between Quotation_Detail and Product2.

trigger QuoteUpdatePN on Quotation_Detail__c (before insert, after insert, before update, after update) {
    Quotation_Detail__c.PN_Link__c =
        [SELECT ID from Product2
         where Product2.UPSERTID__c = :Quotation_Detail__c.Part_Number__c];
}

Problem is I get the above Invalid Bind error, and can not work out why.  Any ideas all?
Anil kumar GorantalaAnil kumar Gorantala
i think your error is in where clause Product2.UPSERTID__c replace it with some variable.
Nick WhiteNick White
OK, I am really new to this, but know that technically this must be possible, so let me describe my challenge in more detail.

I have the Standard Object 'Product2' and a Custom object 'Quotation_Detail__c'
I have a field Part_Number__c in the Quotation_Detail Object, that is populated via an upload from an external system.

I created a Lookup Field called PN_Link__c in the Quotation_Detail object, in order to create a link between Product2 and Quotation_Detail.  The reason is so that we can generate reports etc. using product related data existing in Product2.

As the lookup field PN_Link__c technically contains the ID number and not the text of the part number, I am strugging to fill this field, and create the link with a trigger action.

Perhaps I am going about this the wrong way, so if anyone has any advice, it would be appreciated.
Nick WhiteNick White
I have had some sucess with the following basic Trigger.  This works well when opening an existing record and then saving.

trigger QuoteUpdateGPN2 on Quotation_Detail__c (before update) {
    for (Quotation_Detail__c a : Trigger.new) {
        if (a.GPN_Link__c == null) {
            a.GPN_Link__c = [Select Id FROM Product2 Where Name =:a.Part_Number__c][0].Id;
        }
    }
}

Unfortunately it is not working as part of an "after insert" trigger, as it indicated the field is Read Only.
I understand why, it is indicating as read only, as the field is active, but I am unable to solve.

How can I make this trigger work with "after insert", as well as "before update"

Many thanks