You need to sign in to do that
Don't have an account?
Radha Rathinavel Pandian
update the checbox true in child when the parent is updated
Hi ,
Parent Object: Legal_Description__c
Child Object : Case
Legal description has a lookup field to case. I have a check box(Check_Legal_Description) in the case object, so that whenever I inserted a new record on legal description the checkbox in the case object needs to be checked.
Parent Object: Legal_Description__c
Child Object : Case
Legal description has a lookup field to case. I have a check box(Check_Legal_Description) in the case object, so that whenever I inserted a new record on legal description the checkbox in the case object needs to be checked.
trigger LegalCheck on Legal_Description__c (after insert, after update) {
List<Id> legalId = new List<Id>();
for(Legal_Description__c lg : Trigger.new)
{
legalId.add(lg.Case__c);
}
List<Case> caseRecord = new List<Case>();
for(Case c:[SELECT id,Check_Legal_Description__c,RecordType.name FROM Case WHERE id IN:legalId])
{
c.Check_Legal_Description__c=true;
caseRecord.add(c);
}
update caseRecord;
}
Let us know if this will help you
All Answers
https://help.salesforce.com/articleView?id=000213419&type=1
https://automationchampion.com/2015/02/13/getting-started-with-process-builder-part-1-auto-create-a-record/
I need to implement in trigger
Your code should be like below. Please change the API according to your org
Let us know if this will help you
I am bit confused with where does the Lookup field resides..?? If Legal_Description__c has a look up of Case, then you can update the Checkbox field on Case. If Legal_Description__c is the Parent Object then you cannot update the Case record as there would not be any relation between the Case and the newly inserted Legal_Description__c record.
Can you please confirm as to where does the lookup field resides and which record you want to update.
Thanks,
Jainam Contractor
Legal Description have a lookup for case. I need to enable the checkbox on case object when I added the record in legal description.
Thank you for the code. I have structured with my requirement. Please find below,
trigger LegalCheck on Legal_Description__c (after insert, after update) {
List<Id> legalId = new List<Id>();
for(Legal_Description__c lg : Trigger.new)
{
legalId.add(lg.Case__c);
}
List<Case> caseRecord = new List<Case>();
for(Case c:[SELECT id,Check_Legal_Description__c FROM Case WHERE id IN:legalId])
{
c.Check_Legal_Description__c=true;
caseRecord.add(c);
}
update caseRecord;
}
Here, for my 2 nd step how to get the record type name from the case record?
trigger LegalCheck on Legal_Description__c (after insert, after update) {
List<Id> legalId = new List<Id>();
for(Legal_Description__c lg : Trigger.new)
{
legalId.add(lg.Case__c);
}
List<Case> caseRecord = new List<Case>();
for(Case c:[SELECT id,Check_Legal_Description__c,RecordType.name FROM Case WHERE id IN:legalId])
{
c.Check_Legal_Description__c=true;
caseRecord.add(c);
}
update caseRecord;
}
Let us know if this will help you
I would suggest you to add a check for Case__c != NULL before adding it to the list. It might throw error if Case__c is not populated in the Legal_Description__c record.
IF(lg.Case__c != NULL){
legalId.add(lg.Case__c);
}
And before that SOQL for Loop, check if the List is not NULL && Not empty.
IF(legalId != NULL && legalId.size()>0){
//Your Code
}
You can get the Record Type Name from the below line of code:
string recordtypename =Schema.SObjectType.Case.getRecordTypeInfosById().get(c.recordtypeid).getname();
Let me know if you need more assistance.
Thanks,
Jainam Contractor,
Salesforce Consultant,
Varasi LLC
www.varasi.com
My next requirement is, I have a list of record types A, B and C..... My case object checkbox wants to be enable default when the record type was A or B , orelse it should be unchecked...If I create a legal description for C..my checkbox want to be checked. How can I proceed this?
Hi Amit,
This my new requirement forumhttps://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9060G0000005V7OQAU