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

beginner sfdc apex not working
Hello all !
I am new to SFDC, so I could use some help
I have to custom objects
Product Move and Deliveries
I want a trigger that makes a delivery when I make an order
with the delivery named after my product move
trigger ProductMoveTrigger on Product_Move__c ( after insert) {
List<Delivery__c> deliveries= new List<Delivery__c>();
for(Product_Move__c c : Trigger.new)
{
Delivery__c d = new Delivery__c();
d.Name = c.Store__c + c.Product__c;
deliveries.add(d);
}
try {
insert deliveries;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
where am I going wrong?
Thanks for the help
I am new to SFDC, so I could use some help
I have to custom objects
Product Move and Deliveries
I want a trigger that makes a delivery when I make an order
with the delivery named after my product move
trigger ProductMoveTrigger on Product_Move__c ( after insert) {
List<Delivery__c> deliveries= new List<Delivery__c>();
for(Product_Move__c c : Trigger.new)
{
Delivery__c d = new Delivery__c();
d.Name = c.Store__c + c.Product__c;
deliveries.add(d);
}
try {
insert deliveries;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
where am I going wrong?
Thanks for the help
The code is right. Please share the below information:
1. Is your Delivery__c object's Name fields is Text or Auto-Number : If it is auto number then it will not allow you to assign anything on that, as autonumber field is not writeable. If it is text then it will allow you to store whatever you want.
2. It will be good if you share the exception that you got.
Thanks
Preyanka
exception: Arithmetic expressions must use numeric arguments (it does not allow me to add multiple strings)
And if it works I got delivery names like "a080Y00000A4jrjQAB" which is not a text I put into
If Store__c is a numeric field then while you are trying to save the trigger you will get the above error message at line
d.Name = c.Store__c + c.Product__c;
And as Product__c is a lookup field to Product so you get the delivery name as 18 digit id field, to get the name of the field find the code below
trigger ProductMoveTrigger on Product_Move__c ( after insert) {
List<Delivery__c> deliveries= new List<Delivery__c>();
Product2 pr = new Product2();
for(Product_Move__c c : Trigger.new)
{
Delivery__c d = new Delivery__c();
pr= [Select Name from Product2 where id=: c.Product__c];
if(String.valueof(c.Store__c)!= null)
d.Name = String.valueof(c.Store__c) + pr.Name;
else
d.Name = pr.Name;
deliveries.add(d);
}
try {
insert deliveries;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
Thanks
Preyanka