You need to sign in to do that
Don't have an account?
Intigration v
Test class for attached files in Salesforce
Hi,
can anyone Please help me for writing test class for below code.
global without sharing class checkDoconButton {
webservice static Boolean checkDocVersion(id LeadId){
list<ContentDocumentLink>Doclst= new list<ContentDocumentLink>();
list<string>verifiedDoc= new list<string>();
list<Lead> lstLead=new list<Lead>();
list<string> lstdoctitle=new list<string>();
Boolean isDocument;
lstLead=[select Phone,City__c from Lead where id=:LeadId];
string city='Ver.'+' 0'+lstLead[0].City__c;
Doclst= [SELECT ContentDocumentId,contentdocument.title FROM ContentDocumentLink WHERE LinkedEntityId =:LeadId];
for(ContentDocumentLink doclink:Doclst){
if(doclink.contentdocument.title.contains(city)){
verifiedDoc.add(doclink.contentdocument.title);
}
}
if(verifiedDoc.size()>0){
isDocument=true;
}
else{
isDocument=false;
}
return isDocument;
}
}
can anyone Please help me for writing test class for below code.
global without sharing class checkDoconButton {
webservice static Boolean checkDocVersion(id LeadId){
list<ContentDocumentLink>Doclst= new list<ContentDocumentLink>();
list<string>verifiedDoc= new list<string>();
list<Lead> lstLead=new list<Lead>();
list<string> lstdoctitle=new list<string>();
Boolean isDocument;
lstLead=[select Phone,City__c from Lead where id=:LeadId];
string city='Ver.'+' 0'+lstLead[0].City__c;
Doclst= [SELECT ContentDocumentId,contentdocument.title FROM ContentDocumentLink WHERE LinkedEntityId =:LeadId];
for(ContentDocumentLink doclink:Doclst){
if(doclink.contentdocument.title.contains(city)){
verifiedDoc.add(doclink.contentdocument.title);
}
}
if(verifiedDoc.size()>0){
isDocument=true;
}
else{
isDocument=false;
}
return isDocument;
}
}
Can you try the below test class it gives you around 93% coverage.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Can you try the below test class it gives you around 93% coverage.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Please use updated code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Am getting the below error when i run the test class
"Methods defined as TestMethod do not support Web service callouts".
Thank you!
Getting the same error when i try to run your test class.
"Methods defined as TestMethod do not support Web service callouts".
Thank you!
Can you confirm the code you shared is correct because I dont see any callout in the method which you shared.
Thanks,
am calling this class in javascript button.Please see the javascript code.am getting error if i define the method public instead of webserice to use in javascript button.
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var isDocument=sforce.apex.execute("checkDoconButton", "checkDocVersion", {LeadId:"{!Lead.Id}"});
if(isDocument=="true"){
alert('document already exists');
}
can you help me to resolve this error "Methods defined as TestMethod do not support Web service callouts".
Thank you!
Its working fine now.
Thank you!