You need to sign in to do that
Don't have an account?
Pam 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!
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!
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
https://help.salesforce.com/apex/HTViewHelpDoc?id=process_action_update.htm
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
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.
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