You need to sign in to do that
Don't have an account?
Nash12345
Create trigger to auto populate purchase item's supplier lookup field
Hi All,
I'm trying to create a...well the title says it basically.
The code I currently have doesn't work as I"m getting an "Error: Compile Error: Illegal assignment from List<Purchase_Order__c> to Id at line 7 column 13"
Here's the code:
trigger AutoPopAccountIdOnPi on Purchase_Item__c (before insert) {
for (Purchase_Item__c PIInloop : Trigger.new) {
IF(PIInloop.Supplier__c = null) {
List<Purchase_Order__c> POlist = [SELECT Supplier__c FROM Purchase_Order__c WHERE Name = :PIInloop.Supplier__c];
If(POlist.size() > 0){
PIInloop.Supplier__c = POlist;
} else { PIInloop.Supplier__c = null;
}
}
}
}
Any advice would be much appreciated.
Thanks
I'm trying to create a...well the title says it basically.
The code I currently have doesn't work as I"m getting an "Error: Compile Error: Illegal assignment from List<Purchase_Order__c> to Id at line 7 column 13"
Here's the code:
trigger AutoPopAccountIdOnPi on Purchase_Item__c (before insert) {
for (Purchase_Item__c PIInloop : Trigger.new) {
IF(PIInloop.Supplier__c = null) {
List<Purchase_Order__c> POlist = [SELECT Supplier__c FROM Purchase_Order__c WHERE Name = :PIInloop.Supplier__c];
If(POlist.size() > 0){
PIInloop.Supplier__c = POlist;
} else { PIInloop.Supplier__c = null;
}
}
}
}
Any advice would be much appreciated.
Thanks
Please try this code hope it works, sorry there may be some typo errors.
Please accept my solution as Best Answer if my answer was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
sandhya
Hi Sandya, thanks for your quick reply.
Would you be able to describe what your code actually does?
Reason why I'm asking is because there is still an error on line 15: Purchase_Order__c.Name is not writeable.
Just to add a bit more info:
The Supplier name will already be located in the purchase order. The supplier object is in fact account.
The relationship is as follows Account = Master to Purchase Order = Master to Purchase Item.
Hope this clarifies the situation a bit.
Additional info:
I want the trigger to always activate whenever a new purchase item is created.
what I have assumed is
Firstly you will create Purchase_Order__c then you create Purchase_Item__c when Purchase_Item__c is created you want this Purchase_Item__c name to be updated in the lookup field on Purchase_Order__c?
Thanks and Regards
sandhya
Correct
Thanks for looking at it again Sandhya
What I have observed is an error on line 15: Purchase_Order__c.Name is not writeable.Is this Purchase_Order__c.Name field read-only for you?
Want the trigger always to activate whenever a new purchase item is created---- you can just remove 'before update 'in the trigger.
Thanks and Regards
sandhya