You need to sign in to do that
Don't have an account?
NevDev
Trigger that creates a custom record if a checkbox is true
Hi guys,
I'm new to Apex and I am trying to create a trigger that creates a duplicate record called Section_2_Balance_Sheet on a Contacts record, if a checkbox called Joint_c is true.
I have created a lookup field on the contact record which looks up to contacts. If this lookup field is populated I'd like this clients name to automatically populate the Client_c field in the Section_2_Balance_Sheet record.
Is this possible?
I'm new to Apex and I am trying to create a trigger that creates a duplicate record called Section_2_Balance_Sheet on a Contacts record, if a checkbox called Joint_c is true.
I have created a lookup field on the contact record which looks up to contacts. If this lookup field is populated I'd like this clients name to automatically populate the Client_c field in the Section_2_Balance_Sheet record.
Is this possible?
OR
I seem to be running into an error, also, do I need to write some class before I migrate it from the Sandbox to production?
Here remove "<>" bracket from line 1.
And whenever you are using any custom object or custom field it is appended with __c.
So when I open the Contact record directly from the lookup field, then that record also has the same Sheet_2_Balance_Sheet_c record associated to it.
I'm getting this error now
Error: Compile Error: Invalid type: Section_2_Balance_Sheet at line 5 column 49
So I've managed to correct the issue, but the trigger is creating a duplicate record of the custom object within the same Contact record. What I was hoping to achieve was that it would create a duplicate record within the Contact record that is populating the Contact Lookup field.
I made some edits in the above code. Please update the lookup__c with the field api name which you have created as self lookup on Contact:
Please try this code : Instead of "ContactLookup" in id = ob.ContactLookup use your Contact LookUp Name.
I have tried your code but I receive the below error
I have also tried yours but also receiving errors:
Error: Compile Error: expecting right curly bracket, found '&' at line 4 column 0
Use this code.
They all seemed to come across when I copied your code to my clipboard.
I'm getting the below error now.
Error: Compile Error: Invalid field Spouse__c for SObject Section_2_Balance_Sheet__c at line 5 column 86
So this is what I am looking for
- I have renamed the Contact object as Client
- Client record has a Lookup field to Client called Spouse_c
- Custom object called Section_2_Balance_Sheet__c which is related to Client object
- Inside the Section_2_Balance_Sheet__c I have created a custom checkbox called Joint_c.
- If I create a Section_2_Balance_Sheet__c record and Joint_c = true then I want a Section_2_Balance_Sheet__c record to be created on the Spouse_c record.
Does that make any sense?I just modified my above code. Please try with this:
Error: Compile Error: Variable does not exist: objCloned at line 18 column 27
Just forgot to wrap within braces:
To deploy this, do I need to write a class?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
Handler:
Recursion Handler:
Could you please help me with this final bit?
Do I just add the code you provided above into the trigger?
public class RecursionHandler
{
public static Boolean isrun = true;
}
For some reason I am receoving the below error message on when I try and action this trigger. It was working fine, but now it will not work.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Object_Update_2 caused an unexpected exception, contact your administrator: Object_Update_2: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Object_Update_2: maximum trigger depth exceeded Personal_Finances trigger event AfterInsert for [a013600000EgiJY] Personal_Finances trigger event AfterInsert for [a013600000EgiJZ] Personal_Finances trigger event AfterInsert for [a013600000EgiJa] Personal_Finances trigger event AfterInsert for [a013600000EgiJb] Personal_Finances trigger event AfterInsert for [a013600000EgiJc] Personal_Finances trigger event AfterInsert for [a013600000EgiJd] Personal_Finances trigger event AfterInsert for [a013600000EgiJe] Personal_Finances trigger event AfterInsert for [a013600000EgiJf] Personal_Finances trigger event AfterInsert for [a013600000EgiJg] Personal_Finances trigger event AfterInsert for [a013600000EgiJh] Personal_Finances trigger event AfterInsert for [a013600000EgiJi] Personal_Finances trigger event AfterInsert for [a013600000EgiJj] Personal_Finances trigger event AfterInsert for [a013600000EgiJk] Personal_Finances trigger event AfterInsert for [a013600000EgiJl] Personal_Finances trigger event AfterInsert for [a013600000EgiJm] Personal_Finances trigger event AfterInsert for [a013600000EgiJn]: []: Trigger.Object_Update_2: line 25, column 1