You need to sign in to do that
Don't have an account?
ABC XYZ 39
Help in Create and update trigger logic
HI,
I am writing logic for the scenarios: When a lead is created, few of the fields are written to a
custom object. When the same less record is updated, I want to push the record into the same custom object.
The problem: with creation of a record, fields a,b, c are mandatory to save the record. These would be pushed.
Now, when the same record is updated, details are to be sent. Issue is with every creation scenario, even the update trigger is getting fired- there are 2 sets of records. I have tried to use flags but it didn't help. Eg:
if(flag is true or 'd' field is not updated), update lead. This doesn't work. Please help. Thanks .
I am writing logic for the scenarios: When a lead is created, few of the fields are written to a
custom object. When the same less record is updated, I want to push the record into the same custom object.
The problem: with creation of a record, fields a,b, c are mandatory to save the record. These would be pushed.
Now, when the same record is updated, details are to be sent. Issue is with every creation scenario, even the update trigger is getting fired- there are 2 sets of records. I have tried to use flags but it didn't help. Eg:
if(flag is true or 'd' field is not updated), update lead. This doesn't work. Please help. Thanks .
If you requirement is to only update few fields on a custom object based on a particular Lead record, i will highly recommend you to use Process builder, if super easy to setup.
Find help here:
https://developer.salesforce.com/trailhead/en/business_process_automation/process_builder
If you need to write trigger for this, it would be like this:
(write field API names as per your requirement, correct typos & syntax errors if any)
If this helps you out, please mark it as Best Answer
All Answers
If you requirement is to only update few fields on a custom object based on a particular Lead record, i will highly recommend you to use Process builder, if super easy to setup.
Find help here:
https://developer.salesforce.com/trailhead/en/business_process_automation/process_builder
If you need to write trigger for this, it would be like this:
(write field API names as per your requirement, correct typos & syntax errors if any)
If this helps you out, please mark it as Best Answer
I have written a custom controller to handle this. I am calling afterinsert trigger for new lead created and afterupdate trigger for any subsequent updates.
New Lead : Lead Created with A,B and C mandatory fields created & optional fields unpopulated (Include 'DD' id field)--> Records pushed to the custom object
Lead Update : Only When Lead Updated with changes in a specific section : 'X' with fields 'AA' , 'BB','CC' populated --> Records pushed to the custom object (OR) When lead is updated with optional fields populated with 'DD' id field blank)
Now when a lead is created with A,B,C, and 'DD' unfilled ---> 2 set of Records pushed to custom object one for lead creation scenario
and another for lead updation (Becase 'DD' field is blank) ---> I want to stop this behavior. Can you please clarify whether you have handled the same scenario above?