You need to sign in to do that
Don't have an account?
srinivasasarmahere1.390217033575374E12
Trigger to update field 5 days after the status has not being changed
hi,
I am writing a trigger
There are tow Objects
1. Case (standard $Object)
2. Ticket__C (Custom $Object)
Ticket has a lookup to Case, and a Case can have multiple ticket_C records but a ticket__c can be allocated to one case only.
The requirement is when all the tickets associated to the case are closed but the case status is not closed after 5 days of the ticket__c being closed. the trigger should change the status of the Case to closed.
fields on the objects
Case - Status (Field)
Ticket__C- GLOBAL_Ticket_Status__c (Field)
The trigger should look at all the records of a ticket__c associated to case and check for GLOBAL_Ticket_Status__c== 'Closed' .
If the status of all records are closed and case status is not changed to close for 5 days then change the status of the Case to closed.
This is what i came up with
Trigger Ticket on Ticket__c (after insert, after update) {
Set<Id> closedTicketIds = new Set<Id>();
for (Ticket__c ticket: Trigger.new) {
if (ticket.GLOBAL_Ticket_Status__c == 'closed') {
closedTicketIds.add(ticket.id);
}
}
List<Case> ticketForClosing= [SELECT Status FROM Case
WHERE Ticket__c IN: closedTicketIds];
for (Case c: ticketForClosing) {
c.Status = 'closed';
}
update ticketForClosing;
}
Compile Error: No such column 'Ticket__c' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 34
Any help is appreciated
Thanks
I am writing a trigger
There are tow Objects
1. Case (standard $Object)
2. Ticket__C (Custom $Object)
Ticket has a lookup to Case, and a Case can have multiple ticket_C records but a ticket__c can be allocated to one case only.
The requirement is when all the tickets associated to the case are closed but the case status is not closed after 5 days of the ticket__c being closed. the trigger should change the status of the Case to closed.
fields on the objects
Case - Status (Field)
Ticket__C- GLOBAL_Ticket_Status__c (Field)
The trigger should look at all the records of a ticket__c associated to case and check for GLOBAL_Ticket_Status__c== 'Closed' .
If the status of all records are closed and case status is not changed to close for 5 days then change the status of the Case to closed.
This is what i came up with
Trigger Ticket on Ticket__c (after insert, after update) {
Set<Id> closedTicketIds = new Set<Id>();
for (Ticket__c ticket: Trigger.new) {
if (ticket.GLOBAL_Ticket_Status__c == 'closed') {
closedTicketIds.add(ticket.id);
}
}
List<Case> ticketForClosing= [SELECT Status FROM Case
WHERE Ticket__c IN: closedTicketIds];
for (Case c: ticketForClosing) {
c.Status = 'closed';
}
update ticketForClosing;
}
Compile Error: No such column 'Ticket__c' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 34
Any help is appreciated
Thanks
I think you are trying to do something more like this
Trigger Ticket on Ticket__c (after insert, after update) {
WHERE Id IN: closedTicketIds];
set<Id> caseIDs = new set<Id>();
for(Ticket__c t : ticketForClosing){
set<Case> casesToUpdate = new set<Case>();
for (Case c : [Select Id, Status From Case Where Id In : caseIDs]) {
casesToUpdate.add(c);
update casesToUpdate;
All Answers
I think you are trying to do something more like this
Trigger Ticket on Ticket__c (after insert, after update) {
WHERE Id IN: closedTicketIds];
set<Id> caseIDs = new set<Id>();
for(Ticket__c t : ticketForClosing){
set<Case> casesToUpdate = new set<Case>();
for (Case c : [Select Id, Status From Case Where Id In : caseIDs]) {
casesToUpdate.add(c);
update casesToUpdate;
Compile Error: No such column 'Case__c' on entity 'Ticket__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 39.
this is the error Salesforce is throwing
Compile Error: DML requires SObject or SObject list type: SET<Case> at line 20 column 5
Trigger Ticket on Ticket__c (after insert, after update) {
Set<Id> closedTicketIds = new Set<Id>();
for (Ticket__c ticket: Trigger.new) {
if (ticket.GLOBAL_Ticket_Status__c == 'closed') {
closedTicketIds.add(ticket.id);
}
}
List<Ticket__c> ticketForClosing= [SELECT Id, GLOBAL_Goal__c FROM Ticket__c
WHERE Id IN: closedTicketIds];
set<Id> caseIDs = new set<Id>();
for(Ticket__c t : ticketForClosing){
caseIDs.add(t.GLOBAL_Goal__c);
}
set<Case> casesToUpdate = new set<Case>();
for (Case c : [Select Id, Status From Case Where Id In : caseIDs]) {
c.Status = 'closed';
casesToUpdate.add(c);
}
update casesToUpdate;
}
caseList.addAll(casesToUpdate);
update caseList;
Trigger Ticket on Ticket__c (after insert, after update) {
Set<Id> closedTicketIds = new Set<Id>();
for (Ticket__c ticket: Trigger.new) {
if (ticket.GLOBAL_Ticket_Status__c == 'closed') {
closedTicketIds.add(ticket.id);
}
}
List<Ticket__c> ticketForClosing= [SELECT Id, GLOBAL_Goal__c FROM Ticket__c
WHERE Id IN: closedTicketIds];
set<Id> caseIDs = new set<Id>();
for(Ticket__c t : ticketForClosing){
caseIDs.add(t.GLOBAL_Goal__c);
}
List<Case> casesToUpdate = new List<Case>();
for (Case c : [Select Id, Status From Case Where Id In : caseIDs]) {
c.Status = 'closed';
casesToUpdate.add(c);
}
update casesToUpdate;
}
can you please tell me where do i add the code you have sent me. I will chane the list to set
creating a case and tickets and associated the tickets to the case
Changed the status of two ticket recors to close and the thrid records status is open. however the case was closed despote one of its ticket being open
The requirement was only if all the tickets associated to the case are close then the case status should be closed.
sfdc_ninja, can you please help me put
Thank you
Ask a new question with the working trigger and the requirements.