+ Start a Discussion
Brad007Brad007 

convert 18 character id to 15 id for a custom field

 

Hi, this method need to update three custom fields.
Here i need to retrieve and trim the 18 character id to 15 which i am not sure how to do for the feild
 a.Survey_Opp_Id__c = Opportunity.id;
and the for the field 

a.Survey_Dt__c update it with present date one 1( i.e next day).
And finally update the account Object.
Can anyone please help..
public void sendSurvey()
 {
 List<Account> account = new List<Account>();
 for(Account a:[SELECT a.Survey_Code__c,a.Survey_Dt__c,a.Survey_Opp_Id__c, 
                        (SELECT o.ID from OPPORTUNITIES o
                                 WHERE o.StageName='Active'
                                 AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30
                                 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60) 
                                 FROM Account a])
              {
                                                                                   
                  if(a.Survey_Code__c != 'HF1MoArv')   
             {
               a.Survey_Code__c = 'HF1MoArv';
               //System.debug('Hello');
               system.assertEquals(a.Survey_Code__c, 'HF1MoArv');
               a.Survey_Opp_Id__c = Opportunity.id;
               //a.Survey_Dt__c = s
             } 
        
              }
 }

 

Best Answer chosen by Admin (Salesforce Developers) 
jeremyyjeremyy

Why do you think you need to trim the Id? If you really need this, just do substring(0, 15)

 

a.Survey_Dt__c update it with present date one 1( i.e next day).

 

Date.today().addDays(1); // tomorrow

All Answers

jeremyyjeremyy

Why do you think you need to trim the Id? If you really need this, just do substring(0, 15)

 

a.Survey_Dt__c update it with present date one 1( i.e next day).

 

Date.today().addDays(1); // tomorrow

This was selected as the best answer
Brad007Brad007

Thank you . I need the ID to be trimmed because only 15 character id can be displayed in my reports. From what i have been told as a requirement.