You need to sign in to do that
Don't have an account?
Alexandros Toulis 6
Auto delete record using Apex class/ Process Builder
Hi,
My goal is to be able to delete records in Salesforce, as part of a Process Builder.
As I don't know how to work with Flows I went online and followed this Apex method: https://automationchampion.com/tag/call-an-apex-from-process/
Custom Object: Exec_Ed_Opportunity__c
Related: Events
I want to be able to delete Exec Ed Opportunity related Events based on a field criteria.
Can you help me to build the Apex Class? I get errors when I try.
Thanks,
Alexandros
My goal is to be able to delete records in Salesforce, as part of a Process Builder.
As I don't know how to work with Flows I went online and followed this Apex method: https://automationchampion.com/tag/call-an-apex-from-process/
Custom Object: Exec_Ed_Opportunity__c
Related: Events
I want to be able to delete Exec Ed Opportunity related Events based on a field criteria.
Can you help me to build the Apex Class? I get errors when I try.
Thanks,
Alexandros
The Apex Class now is like:
public class DeleteUnconfirmedEvents{
@InvocableMethod
public static void eventDelete(List<id> eventId){
Event evnt = [Select Id, WhatId from Event where Id in: eventId LIMIT 1];
List<Event> eventList = new List<Event>();
eventList = [select id From Event where WhatId =: evnt.WhatId and Event_Status__c = 'Not Confirmed'];
if(!eventList.isEmpty()){
delete eventList;
}
}
}
I still get this error: Error Occurred: An Apex error occurred: System.QueryException: List has no rows for assignment to SObject
Is it related to this known issue?
https://help.salesforce.com/articleView?id=000328824&type=1&mode=1
How can I change the class to not have the error?
Thanks,
Alexandros
All Answers
public class ExecEdOpportunity {
@InvocableMethod
public static void OppDelete(List EventIds) {
List<Exec_Ed_Opportunity__c> eedList = [select id, name (select id From events) from Exec_Ed_Opportunity__c where id IN:EventIds];
delete eedList ;
}
}
Please let me know if it solves your problem
Try below code:
I also get the below error:
Error: Compile Error: Missing '<' at 'EventIds' at line 3 column 39
so to remove the first error you need List<id> eventIds
for your condition part you can put the if condtion before the delete event. i hope it will work.
Can you re-write the apex class for me? I am still getting errors. Will this apex class delete the events, right?
The Apex Class now is like:
public class DeleteUnconfirmedEvents{
@InvocableMethod
public static void eventDelete(List<id> eventId){
Event evnt = [Select Id, WhatId from Event where Id in: eventId LIMIT 1];
List<Event> eventList = new List<Event>();
eventList = [select id From Event where WhatId =: evnt.WhatId and Event_Status__c = 'Not Confirmed'];
if(!eventList.isEmpty()){
delete eventList;
}
}
}
I still get this error: Error Occurred: An Apex error occurred: System.QueryException: List has no rows for assignment to SObject
Is it related to this known issue?
https://help.salesforce.com/articleView?id=000328824&type=1&mode=1
How can I change the class to not have the error?
Thanks,
Alexandros
Can you run your query in query editor.
put a debug statement after
Event evnt = [Select Id, WhatId from Event where Id in: eventId LIMIT 1];
system.debug('evnt******'+evnt);
and also
eventList = [select id From Event where WhatId =: evnt.WhatId and Event_Status__c = 'Not Confirmed'];
system.debug('eventList ******' +eventList +eventList.size() );
Please give the screeshot so that i cna help you in a better way.
Thanks
Sorry I have never worked with Apex Class before.
hello alexandros,
Yes this way only.
You need to check in logs when you perform the process. what you are getting in these
It's not working fine!
Please mark it as solved as it will still be in unsolved thread and you will be getting unwanted mails .
Thanks