You need to sign in to do that
Don't have an account?
Trigger error: execution of AfterUpdate caused by: System.StringException: Invalid id: 0001282:
Hi!
I Wonder if anyone could help me on this.
I Have a custom object named "Contratacao__c" and when the field "Status_do_Contrato__c" is filled with the value 'Emitir Boletos' it was suposed to create a new record on the related custom object "Faturamento__c".
But after insert or update a "Contratacao__c" record, the trigger below returns the following error:
Erro:O acionador CreateBilling do Apex causou uma exceção inesperada. Entre em contato com o administrador: CreateBilling: execution of AfterUpdate caused by: System.StringException: Invalid id: 0001282: Trigger.CreateBilling: line 8, column 36
Which means that the "Faturamento__c.Contrato__c" field related to the "Contratacao__c.name" is not filled with the right value.
In the above example, I have a record in "Contratacao__c" registered as "0001282" and the related record "Faturamento__c" should have a field "Faturamento__c.Contrato__c" filled with the same "0001282"
Faturamento__c.Contrato__C: Relationship field (Master and Detail)
Contratacao__c.name = automatica numbered
What am I doing wrong? How to Fix it?
Here´s the code:
trigger CreateBilling on Contratacao__c (after update, after insert) { Contratacao__c[] Contratos = Trigger.new; if (Contratos[0].Status_do_Contrato__c == 'Emitir Boletos') { Faturamento__c Billing = new Faturamento__c ( Contrato__c = Contratos[0].name, F__c = Contratos[0].Total_do_Contrato__c, V__c = Contratos[0].Nascimento__c); insert Billing; } } |
Update this
Contrato__c = Contratos[0].name
to
Contrato__c = Contratos[0].Id
In your trigger you are assiging String value in ID Type field
Your trigger will be like this
All Answers
Update this
Contrato__c = Contratos[0].name
to
Contrato__c = Contratos[0].Id
In your trigger you are assiging String value in ID Type field
Your trigger will be like this
Thanks a lot! worked pretty fine.
Hi Shashikant Sharma,
What sugestion could you give me to make the trigger builds 12 Billings?
Can I have a loop inside a Trigger?
Any idea?
Thanks in advance!