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

How to map custom fields with Apex Triggers?
I need help on creating an apex trigger that maps one custom object currency field to another custom object currency field.
IF (ObjectA.CustomFieldA != NULL)
Then (ObjectB.CustomFieldB = ObjectA.CustomFieldA)
Else (ObjectB.CustomFieldB = 0.00)
IF (ObjectA.CustomFieldA != NULL)
Then (ObjectB.CustomFieldB = ObjectA.CustomFieldA)
Else (ObjectB.CustomFieldB = 0.00)
I think, I'm not getting you at all, could you give me a little bit more of information?, like:
Which object is executing the trigger?
What is the relationship between ObjectA and ObjectB? (Lookup from ObjA to objB or viceversa)
As a quick possible solution is:
Create a Lookup from ObjB to ObjA
From the ObjA trigger create a map with Trigger.newMap (map<Id, ObjectA__c>)
Also create a set of ObjectA's Ids with a for loop
Get a list of ObjectB records with a SOQL filtering with the ObjA's set
Create a for loop to create a map of ObjectB (map<string, ObjectB>) where the string will be the ObjectA lookup field value
Do another for loop with the trigger.new where your If statement is going to be:
view sourceprint?
Update the list pf ObjectB records.
Hope this helps you.
Emmanuel Cruz
Error: Compile Error: Variable does not exist: ProspectMap at line 5 column 17
You haven't created the map there "ProspectMap", you have to create that one from a list of i360__Prospect__c which you will get from the set of i360__Appointment__c' ids, here a better approach:
Be aware that you need to create the lookup field i360__Appointment__c on i360__Prospect__c and this field should contain a record related.
Since you are using ids, your trigger need to change to after insert. I also recommend to add a line to verify if the prospect is on the map to avoid an error.
Let me know how it goes.
I'm getting this error:
Error: Compile Error: No such column 'i360__Appointment__c' on entity 'i360__Prospect__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 52
And with "record related" I mean that the Prospect record should point to any Appointment record in that field, for example you have appointmentA and PropectB, if PropestB is not pointing to AppointmentB, ProspectB will never get the value that you are looking for from Appointment.
In the other hand, I realize that the logic that we are creating is not going to work, because you need to create the lookup field in Appointment insteat of in Prospect, because you are creating the appointment assuming that the prospect already have a relationship with the appointment, but this can be possible since the appointment is just going to be created. Sorry for that!! :(
Your trigger will finally look like this.
You need to delete the first lookup field in Prospect and create a new one but this time in appointment. Make sure to use the correct APi names for the fields, the API name for this field need to be i360__Prospect__c.
prospect.Appointment_Quoted_Price__c = $0.00 no matter what I enter in Appointment.i360__Quoted_Amount__c.
So if I enter $100.00 in Appointment.i360__Quoted_Amount__c,
prospect.Appointment_Quoted_Price__c = $0.00
Please add system.debug(ProspectSet) after line 11
Also add system.debug(ProspectMap) after line 17
Try verifying the if statement adding a system.debug(Appointment.i360__Quoted_Amount__c) before line 23
Finally debug the propest list adding system.debug(ProspectsToUpdate) before line 31
Copy your debug log and paste it here to see what is happening.
Here is the current code:
With apex code, create a Prospect, then create an Appointment related to the Prospect and then click the log tab and open the last executed operation. Finally click the debug only checkbox, copy and paste the code here.