You need to sign in to do that
Don't have an account?
Laurie Drew
Method does not exist or incorrect signature: void startswith(String) from the type Id
Hello Friends,
I am getting an error trying to compile my class that I am hoping someone can assist with. My requirement is to check a box on the Case object when an attachment is added to the case. I am getting the message 'Method does not exist or incorrect signature: void startswith(String) from type Id" .
Any assistance would be greatly appreciated. Here's my code:
trigger AttachmentPresent on Attachment (after insert) {
Set<Id> caseIds = new Set<Id>();
for(Attachment att : Trigger.New) {
//Check if added attachment is related to Case or not
if(att.ParentID.startswith('500')) {
caseIds.add(att.ParentId);
}
}
if(!caseIds.isEmpty()) {
CaseHandler.attachmentAdded(caseIds);
}
}
And Class:
public with sharing class CaseHandler {
public static void attachmentAdded(Set<Id> caseIds) {
List<Case> updateCases = new List<Case>();
List<Case> caseList = [SELECT Id, has_Attachment__c FROM Case WHERE Id IN: caseIds];
for(Case myCase : caseList) {
if(!myCase.has_Attachment__c) {
myCase.has_Attachment__c = true;
updateCases.add(myCase);
}
}
if(!updateCases.isEmpty()) {
update caseList;
}
}
}
I am getting an error trying to compile my class that I am hoping someone can assist with. My requirement is to check a box on the Case object when an attachment is added to the case. I am getting the message 'Method does not exist or incorrect signature: void startswith(String) from type Id" .
Any assistance would be greatly appreciated. Here's my code:
trigger AttachmentPresent on Attachment (after insert) {
Set<Id> caseIds = new Set<Id>();
for(Attachment att : Trigger.New) {
//Check if added attachment is related to Case or not
if(att.ParentID.startswith('500')) {
caseIds.add(att.ParentId);
}
}
if(!caseIds.isEmpty()) {
CaseHandler.attachmentAdded(caseIds);
}
}
And Class:
public with sharing class CaseHandler {
public static void attachmentAdded(Set<Id> caseIds) {
List<Case> updateCases = new List<Case>();
List<Case> caseList = [SELECT Id, has_Attachment__c FROM Case WHERE Id IN: caseIds];
for(Case myCase : caseList) {
if(!myCase.has_Attachment__c) {
myCase.has_Attachment__c = true;
updateCases.add(myCase);
}
}
if(!updateCases.isEmpty()) {
update caseList;
}
}
}
The issue is att.ParentID is the Id type of field and you are checking with wrong type so you need to Check list String.valueOf(att.ParentID).startsWith();
Then you will not get any error here.
Please let me know if still you are facing any issue.
Thanks
Hemant
All Answers
The issue is att.ParentID is the Id type of field and you are checking with wrong type so you need to Check list String.valueOf(att.ParentID).startsWith();
Then you will not get any error here.
Please let me know if still you are facing any issue.
Thanks
Hemant
if(((String)att.ParentID).startswith('500')) {
caseIds.add(att.ParentId);
}
The trigger will be
Please execute following code in the anonymous window :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com