• Intigration v
  • NEWBIE
  • 20 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 12
    Replies
Hi,
I am making a REST Api call and getting the Access token in the Response.I am getting the full length Access Token when i try in the Postmen.But facing issue in getting full length Access token when i making Api call in Apex,some part of the string only returning when i put the debug logs.

can anyone know why this happes and the length of the string like 1325 .
Please Suggest
Thank you!

 
Hi,
I have a requirement to get the files attached with specific title,am trying to filter the records with below query but it is giving me zero results.
There is already two files attached to my Lead record with the title "Customer reviwed".But it is giving me zero results when am applying filter with title.
Please can anyone helpme how can i query the title from contentdocumentLink object.

SELECT ContentDocumentId,contentdocument.title FROM ContentDocumentLink WHERE LinkedEntityId =:LeadId AND contentdocument.title='%Customer%'
Thank you!
Hi,
Can some one please help me on this test class error.I have used the Apex class in my java script button to display error message based on the return boolean value.
Javascript button code:

{!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');
}
Apex class:
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;
    }

}
Test Class:
@istest
public class checkDoconButtonTest {
   @istest
static void  checkdocbutton() {
    Test.startTest();
    Lead l = new Lead();
    l.LastName='sample';
    l.Company='sample';
    l.Status='Qualified';
    l.City__c='hyderabad';
    insert l;
    ContentVersion cv = new ContentVersion();
cv.Title = 'Ver. 0hyderabad';
cv.PathOnClient = 'TesthyderabadDocument.pdf';
cv.VersionData = Blob.valueOf('Test Content');
cv.IsMajorVersion = true;
Insert cv;

//Get Content Documents
Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;

//Create ContentDocumentLink 
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = l.Id;
cdl.ContentDocumentId = conDocId;
cdl.shareType = 'V';
Insert cdl;
    
   Boolean check= checkDoconButton.checkDocVersion(l.id);
    system.assertEquals(True, check);
    Test.stopTest();
}
}

Getting the error :Methods defined as TestMethod do not support Web service callouts
can anyone please tell me how can i pass this test class?
Thank you!
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;
    }

}
Hi,
I have a requirement to display the files attached to work order object on vfpage and what ever the files that are selected by the user need to be send through mail.
Need to display button on workorder and when he clicks that button list of files need to be diaplayed on page .After selecting the files it should send to user by Email.
Please share the example code to achieve this requirement.

Thank you!
Hi,
can anyone please suggest,am getting the error below when i click the button.

"Invalid or unexpected token "

window.open("/apex/APXTConga4__Conga_Composer
?serverUrl={!API.Partner_Server_URL_370}
&Id={!URLENCODE(WorkOrder__c.Id)}

&ReportId=[Measurements]00Oj0000000imnL,[Standards]00Oj0000000imnp,[Tasks1]00Oj0000000aFdQ,[Account]00Oj0000000jB2N
&QueryId=[Tasks]a0Xf100000Ao7bI,[Signature]a0X3Z00000SSFiG,[Electrical]a0X3Z00000SSZmq,[EccentricityTest]a0X3Z00000W37Uc,[SensitivityTest]a0X3Z00000W37W0,[RepeatabilityTest]a0X3Z00000W37W5,[LinearityTest]a0X3Z00000W37WA

&TemplateGroup=CalibrationCert
&TemplateId={!WorkOrder_c.Conga_Report_WFRULES_c}
&contentShareType=V
&contentVisibility=AllUsers

&DefaultPDF=1
&_AC0=1


&DC={!IF( WorkOrder_c.Work_Order_Status_c  = "In Progress", 1, 0)}

&OFN=SR+{!WorkOrder__c.Name}+Ver.+0{!WorkOrder_c.Versionc}+{!WorkOrderc.Equipmentc}+TAG+{!WorkOrderc.EquipmentTagc}+SN+{!WorkOrderc.SerialNoc}+{!WorkOrderc.ServiceDateTEXT_c}

&CSvisible=1
&CSBusinessUnit=TechnicianOnly
&CSrecipient1={!WorkOrder_c.PrimaryTechnicianId_c}
&CSRole1=IN_PERSON_SIGNER
&CSRoutingType=Serial

&DS7=1141
&DS7Preview=1
&BML={!WorkOrder_c.PrimaryTechnician_c}+!!!PLEASE+REVIEW+CAREFULLY+BEFORE+CONTINUING
&AttachmentParentId={!Case.Id}")
Hi,
can someone please help me to resolve the issue.An error message should be displayed when there is already file attached to Lead object.
I have written trigger to display error message but it is giving error when am trying to upload the file first time as well.
It should display the message only there is already document uploaded to that Lead record.

trigger ContentDocumentTrigger on ContentDocumentLink (before insert) {
  Set<Id> setParentId = new Set<Id>();
    list<ContentDocumentLink>Doclst= new list<ContentDocumentLink>();
    for (ContentDocumentLink cdl : trigger.new ) {
        setParentId.add(cdl.LinkedEntityId);        
    }
   Doclst= [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =:setParentId];
    system.debug('Doclst.size()'+Doclst.size());
    
    
      for (ContentDocumentLink cdl : trigger.new ) {
          if(Doclst.size()>0){
            cdl.adderror('document already exists');  
    }  
      }
 }
Hi,
I am making a REST Api call and getting the Access token in the Response.I am getting the full length Access Token when i try in the Postmen.But facing issue in getting full length Access token when i making Api call in Apex,some part of the string only returning when i put the debug logs.

can anyone know why this happes and the length of the string like 1325 .
Please Suggest
Thank you!

 
Hi,
I have a requirement to get the files attached with specific title,am trying to filter the records with below query but it is giving me zero results.
There is already two files attached to my Lead record with the title "Customer reviwed".But it is giving me zero results when am applying filter with title.
Please can anyone helpme how can i query the title from contentdocumentLink object.

SELECT ContentDocumentId,contentdocument.title FROM ContentDocumentLink WHERE LinkedEntityId =:LeadId AND contentdocument.title='%Customer%'
Thank you!
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;
    }

}
Hi,
can someone please help me to resolve the issue.An error message should be displayed when there is already file attached to Lead object.
I have written trigger to display error message but it is giving error when am trying to upload the file first time as well.
It should display the message only there is already document uploaded to that Lead record.

trigger ContentDocumentTrigger on ContentDocumentLink (before insert) {
  Set<Id> setParentId = new Set<Id>();
    list<ContentDocumentLink>Doclst= new list<ContentDocumentLink>();
    for (ContentDocumentLink cdl : trigger.new ) {
        setParentId.add(cdl.LinkedEntityId);        
    }
   Doclst= [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =:setParentId];
    system.debug('Doclst.size()'+Doclst.size());
    
    
      for (ContentDocumentLink cdl : trigger.new ) {
          if(Doclst.size()>0){
            cdl.adderror('document already exists');  
    }  
      }
 }

Please help me with writing a test for this code!

public with sharing class AttClass {
  
    Id PageId;
    Id contentDocId;
    public Id contentId{get; set;}
    public Blob Body {get;set;}
    public String Name {get;set;}
    id cand;
    public ContentDocument imgExist(Id c){
        try{
            contentDocId = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =: c LIMIT 1].ContentDocumentId;
            if(contentDocId == null){return null;}
            ContentDocument cdRec = [SELECT Id, LatestPublishedVersionId FROM ContentDocument WHERE Id =: contentDocId];
            System.debug('LatestPublishedVersionId:' + cdRec.LatestPublishedVersionId);
            if(cdRec == null){return null;}
            return cdRec;	
        } catch (Exception e){
            return null;
        }
    } 		
	
    public AttClass() {
		/*cand = [SELECT Id, Name FROM Candidate__c
                WHERE Id = :ApexPages.currentPage().getParameters().get('id')];*/
		//Name = 'Candidate ' + cand.Name + ' Photo';
        cand = ApexPages.currentPage().getParameters().get('id');
		ContentDocument cd = imgExist(cand);
		if(cd != null){
			contentId = cd.LatestPublishedVersionId;
			System.debug('LatestPublVersionId:  ' + contentId);
        }    
    }

    public PageReference save() { 
		if(contentId == null){
			ContentVersion ConVer = createContentVersion(Name, Body);
			contentId = ConVer.Id;
    		 createContentLink(contentId, cand); 
			return null;
        }
        else {
            ApexPages.Message myMsg = new  ApexPages.Message(ApexPages.Severity.ERROR,'You have one photo');
            ApexPages.addMessage(myMsg); 
            return null;
        }
    }    
    

	public static ContentVersion createContentVersion(String Name, Blob Body){
		ContentVersion ConVer = new ContentVersion();
		ConVer.VersionData = Body;
		ConVer.Title = Name;
		ConVer.PathOnClient = Name;

		try {
      		insert ConVer;
      		return ConVer;
    	} catch(DMLException e) {
      		System.debug(e);
      		return null;
    	}
	}

	public static void createContentLink(String contentVersionId, String recordId){

		ContentDocumentLink cdLink = new ContentDocumentLink();
		cdLink.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion
									WHERE Id =: contentVersionId].ContentDocumentId;
		cdLink.LinkedEntityId = recordId;
		cdLink.ShareType = 'I';
		cdLink.Visibility = 'AllUsers';

		try{
			insert cdLink;
			
		} catch(DMLException e){
			System.debug(e);
			
		}
	}                    
}