function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pam B 1Pam B 1 

How do I get a field on a custom object to update a custom field on a standard object?

I have a custom object: Japan CCA Form
With a checkbox field: CCA_Agree_to_terms__c  
I want to update a custom checkbox field on the case object: CCA_Received
When the CCA_Agree_to_terms_c is true
 
How can I accomplish this?  I have spent hours chasing my tail. I feel the answer is a trigger, which I have no experience in. Please help!
 
Best Answer chosen by Pam B 1
Ajay K DubediAjay K Dubedi
Hi Pam
Here is the solution to get a field on a custom object to update a custom field on a standard object(Trigger)

Apex Class:-

public class UpdateCaseChexbox 
{
  public static void fieldUpdateMethod(List<japan_CCA__c> CCAList)
  {
      
      List<Case> newcaselist=new List<Case>();
      set<Id> setid=new set<Id>();
      for(japan_CCA__c ids:CCAList)
      {
          setid.add(ids.Case__c);
      }
     List<Case> caseList=[SELECT CCA_Received__c from Case where Id In:setid];
      
    for(japan_CCA__c cc:CCAList)
    {
        if(cc.CCA_Agree_to_terms__c==true)
        {
            for(case ca:caseList)
            {
                Case c=new Case();
                c.Id=ca.Id;
                c.CCA_Received__c=true;
                newcaselist.add(c);
            }
        }
    }
      update newcaselist;
  }
}

Trigger:-

trigger japanCCATrigger on japan_CCA__c (after update)
{
   UpdateCaseChexbox.fieldUpdateMethod(trigger.new);
}

Please mark it as best answer if you find it helpful.

Thank you
Ajay Dubedi

 

All Answers

Raj VakatiRaj Vakati
You can able to do it with process builder  

https://help.salesforce.com/apex/HTViewHelpDoc?id=process_action_update.htm
Ajay K DubediAjay K Dubedi
Hi Pam
Here is the solution to get a field on a custom object to update a custom field on a standard object(Trigger)

Apex Class:-

public class UpdateCaseChexbox 
{
  public static void fieldUpdateMethod(List<japan_CCA__c> CCAList)
  {
      
      List<Case> newcaselist=new List<Case>();
      set<Id> setid=new set<Id>();
      for(japan_CCA__c ids:CCAList)
      {
          setid.add(ids.Case__c);
      }
     List<Case> caseList=[SELECT CCA_Received__c from Case where Id In:setid];
      
    for(japan_CCA__c cc:CCAList)
    {
        if(cc.CCA_Agree_to_terms__c==true)
        {
            for(case ca:caseList)
            {
                Case c=new Case();
                c.Id=ca.Id;
                c.CCA_Received__c=true;
                newcaselist.add(c);
            }
        }
    }
      update newcaselist;
  }
}

Trigger:-

trigger japanCCATrigger on japan_CCA__c (after update)
{
   UpdateCaseChexbox.fieldUpdateMethod(trigger.new);
}

Please mark it as best answer if you find it helpful.

Thank you
Ajay Dubedi

 
This was selected as the best answer
Pam B 1Pam B 1
Hey Ajay, 

Thanks for your assistance. I copied this:
public class UpdateCaseChexbox 
{
  public static void fieldUpdateMethod(List<japan_CCA__c> CCAList)
  {
      
      List<Case> newcaselist=new List<Case>();
      set<Id> setid=new set<Id>();
      for(japan_CCA__c ids:CCAList)
      {
          setid.add(ids.Case__c);
      }
     List<Case> caseList=[SELECT CCA_Received__c from Case where Id In:setid];
      
    for(japan_CCA__c cc:CCAList)
    {
        if(cc.CCA_Agree_to_terms__c==true)
        {
            for(case ca:caseList)
            {
                Case c=new Case();
                c.Id=ca.Id;
                c.CCA_Received__c=true;
                newcaselist.add(c);
            }
        }
    }
      update newcaselist;
  }
}

in a new apex class and got the below error: 
Error: Compile Error: Invalid type: japan_CCA__c at line 3 column 59
When trying to save. 
Ajay K DubediAjay K Dubedi
Hi Pam,

You need to replace your API name according to this.

My object is:-
object Name:- japan CCA 
And Object API Name is:- japan_CCA__c

Hope it helps you.

Thank You,
Ajay Dubedi