function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AArzaAArza 

Method does not exist or incorrect signature: void replace(String, Datetime) from the type String

Error: Method does not exist or incorrect signature: void replace(String, Datetime) from the type String

also, i noticed that even when i comment out the this line of code it is still returning the same error. please suggest.
 
for(ContentDocumentLink clIterator : trigger.new) {
        string strObjPrefix = String.valueOf(clIterator.LinkedEntityId).substring(0, 3);
        if(strObjPrefix == Appointment__c.sObjectType.getDescribe().getKeyPrefix()) {
            setCntDocIds.add(clIterator.ContentDocumentId);
            setAccIds.add(clIterator.LinkedEntityId);
            //Id str =setAccIds[0];
            Set<Id> str = new set<Id>(setAccIds);
            Appointment__c app= [select id from Appointment__c where id =:str limit 1] ;
			 
            system.debug('Email Body');//debug appointment
            string filename =filestitlemaps.get(clIterator.ContentDocumentId); 
            string accountname = accnamemaps.get(clIterator.LinkedEntityId);
            Set<String> KeywordSet = new Set<String>();
            
            
            
            Program_Setting__mdt[] programs = [SELECT Email_Body__c, Keyword__c, Keyword1__c FROM Program_Setting__mdt];        
            //if(filename.containsAny(programs[0].Keyword__c)){
            if((programs[0].keyword__c).containsAny(Filename)){
                
              Contact c = [Select id, name from contact where name='Ultragenyx PV'];
           //  List<string> toAddress = new List<string>();
            // toAddress.add('iamaarza@gmail.com');
             
 

                          
            EmailTemplate emailTemplate = [select Id, Subject, HtmlValue, Body from EmailTemplate where Id ='00X0i000000PGf1']; 
                String subject = emailTemplate.Subject;
                               //query appointment record pass values to replace the merge fields
        
            String plainBody = emailTemplate.Body;
            plainBody = plainBody.replace('{!app.Name}', app.Name);
            string s = string.valueOfGmt(app.Appointment_Start_Date__c);
            //plainBody = plainBody.replace('{!app.Appointment_Start_Date__c}', app.Appointment_Start_Date__c); 
            plainBody = plainBody.replace('{!app.Appointment_Start_Date__c}', s); 
                
           
      
              Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    mail.setTemplateId('00X0i000000PGf1');
                   // mail.setToAddresses(toAddress);
                    //mail.setSubject('test subject');
                    mail.setTargetObjectId(c.Id);
                    //mail.setWhatId(c.Id);
                    mail.setSaveAsActivity(false);
                    mail.setUseSignature(false);
                    
                    
                    List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
                    allmsg.add(mail); 
                     
        }
        
    }
}
}

 
Best Answer chosen by AArza
Shubham_KumarShubham_Kumar
Hi
Your error says "incorrect signature: void replace(String, Datetime)" notice that the second parameter is the "DateTime" here which i don`t see any where in your code except the line 35 which you have commented. The line 36 has string as the parameter so i don`t think the error is in line 36.
Please try to save the code once again and then try to run it as i don`t see this error anywhere in the code.

All Answers

Sunil RathoreSunil Rathore
Hi,

The issue is encountering due to the following line:
 
plainBody = plainBody.replace('{!app.Appointment_Start_Date__c}', s);
Here you are replacing DateTime value with a String value.

Instead of the above line, you can use:
plainBody = plainBody.replace(string.valueOfGmt({!app.Appointment_Start_Date__c}), s);
Hope this will help you. If does then please mark it as best answer so it can also help others.

Many Thanks,
Sunil Rathore

 
Shubham_KumarShubham_Kumar
Hi
Your error says "incorrect signature: void replace(String, Datetime)" notice that the second parameter is the "DateTime" here which i don`t see any where in your code except the line 35 which you have commented. The line 36 has string as the parameter so i don`t think the error is in line 36.
Please try to save the code once again and then try to run it as i don`t see this error anywhere in the code.
This was selected as the best answer
AArzaAArza
I was able to save the code without any errors but however whenever I am trying to upload a file i am seeing below error message 

Error: There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger sfdctest caused an unexpected exception, contact your administrator: sfdctest: execution of BeforeInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Appointment__c.Name: Trigger.sfdctest: line 54, column 1".

line 54: 
            plainBody = plainBody.replace('{!app.Name}', app.Name);
            string s = string.valueOfGmt(app.Appointment_Start_Date__c);
            //plainBody = plainBody.replace('{!app.Appointment_Start_Date__c}', app.Appointment_Start_Date__c); 
            plainBody = plainBody.replace('{!app.Appointment_Start_Date__c}', s);

Any idea What the error means.

 
Sunil RathoreSunil Rathore
Hi AArza,

You are using the fields of Appointment without retrieving in the query.

Replace the query 
Appointment__c app= [select id from Appointment__c where id =:str limit 1] ;

with the following query:
Appointment__c app= [select id, Name, Appointment_Start_Date__c from Appointment__c where id =:str limit 1] ;

Let me know if it solves your problem.

Many Thanks,
Sunil Rathore
Shubham_KumarShubham_Kumar
Hi  AArza
This error occurs when you try to use Sobject Fields without retrieving it in your query.
In your case you have used "app.Name" and "app.Appointment_Start_Date__c " without retrieving it in your query.
if you just put these fields in your query then it should work.
Appointment__c app= [Select id, Name, Appointment_Start_Date__c from Appointment__c Where id =:str Limit 1] ;
Hope this helps. Do let me know if you have any further queries.

P.S: Please marks this as the best answer if this helped.

Regards
Shubham Kumar
 
AArzaAArza
Thanks guys, you were of great help. appreciate it.
AArzaAArza
Guys, the merge fields from the email body doesn't show up when the above trigger sends out an email. any idea why the merge fields are not showing up.