You need to sign in to do that
Don't have an account?
Jyosi jyosi
To update contat when the when case is closed
Hello Every one,
I need to update the contact when the Case is closed.
I wrote the code but its not triggering.
Below is my code
public void UpdateRepStatus(List<Case> CompliancesurveryDetailsLists, Map<ID,Case> oldCompliancesurveryDetailsmap)
{
set<Id> CaseId= new Set<Id>();
List<Contact> LstcntUpdate= new List<Contact>();
List<Case> LstCases=new List<Case>();
for(Case Cases:CompliancesurveryDetailsLists)
{
CaseId.add(Cases.Id);
CaseId.add(Cases.Contact__c);
}
LstCases=[SELECT Id,Status,Contact__c FROM Case where status='closed' AND ID IN:CaseId AND Contact__c IN: CaseId LIMIT 1];
system.debug('LstCases====>>>'+LstCases);
if(LstCases.size()>0)
{
for(Case Cases:LstCases)
{
contact cnt= new contact();
cnt.Id=Cases.Contact__c;
cnt.Rep_Status__c='Terminated';
LstcntUpdate.add(cnt);
}
update LstcntUpdate;
}
Trigger Class
if(Trigger.isBefore && Trigger.isUpdate) {
CasesTriggerHandler.UpdateRepStatus(Trigger.New, Trigger.oldMap);
}
thanks for help.
Regards,
Jyo
I need to update the contact when the Case is closed.
I wrote the code but its not triggering.
Below is my code
public void UpdateRepStatus(List<Case> CompliancesurveryDetailsLists, Map<ID,Case> oldCompliancesurveryDetailsmap)
{
set<Id> CaseId= new Set<Id>();
List<Contact> LstcntUpdate= new List<Contact>();
List<Case> LstCases=new List<Case>();
for(Case Cases:CompliancesurveryDetailsLists)
{
CaseId.add(Cases.Id);
CaseId.add(Cases.Contact__c);
}
LstCases=[SELECT Id,Status,Contact__c FROM Case where status='closed' AND ID IN:CaseId AND Contact__c IN: CaseId LIMIT 1];
system.debug('LstCases====>>>'+LstCases);
if(LstCases.size()>0)
{
for(Case Cases:LstCases)
{
contact cnt= new contact();
cnt.Id=Cases.Contact__c;
cnt.Rep_Status__c='Terminated';
LstcntUpdate.add(cnt);
}
update LstcntUpdate;
}
Trigger Class
if(Trigger.isBefore && Trigger.isUpdate) {
CasesTriggerHandler.UpdateRepStatus(Trigger.New, Trigger.oldMap);
}
thanks for help.
Regards,
Jyo
1. Create a process builder on the object Opportunity and enable 'Create or edited'
2. Then set the condition as 'isClosed' = true
3. Then in the immediate action, selecte 'Update Record'
4. Then select the fields you want to update in the contact object.
5. Then activate your process builder
To know more about process builder check this link - https://developer.salesforce.com/trailhead/force_com_declarative_beginner/business_process_automation/process_builder
Thanks,
karanrajs.com
When i change this i am getting the below Error
Review all error messages below to correct your data.
Apex trigger QP_CaseTrigger caused an unexpected exception, contact your administrator: QP_CaseTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Class.CaseshandlerClass.UpdateRepStatus: line 86, column 1
Thanks
Regards,
Jyo
Thanks,
Karanraj
http://www.karanrajs.com
You can try below code
if(Trigger.isAfter&& Trigger.isUpdate) {
CasesTriggerHandler.UpdateRepStatus(Trigger.New, Trigger.oldMap);
}
Regards,
Bhanu Mahesh