How to convert String to record Id in Salesforce?
String recordId = '01I20000000VyKGAAN'; Id newId = Id.valueOf(recordId);
Note: Here String recordId
should be a valid record id. Salesforce Id is system generated Id and we cannot generate it.
String recordId = '01I20000000VyKGAAN'; Id newId = Id.valueOf(recordId);
Note: Here String recordId
should be a valid record id. Salesforce Id is system generated Id and we cannot generate it.
The below sample code is used to convert String to Date data type using Apex
String todate = '12/25/2015'; Date dt = Date.parse(todate);
List<account> objList = new List<account>(); objList.add(new Account(name = 'Test Account'); objList.clear(); //Clear the account list
String strMail = 'testmail@gmail.com'; if(!Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}', strMail)) { //Your error message }
Here in below example, there is a custom field Active__c
in Contact object. On a button click want to update Active__c
field status to true.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} if(confirm("Do you want to active this Contact?") == true) { var objC = new sforce.SObject("Contact"); objC.Id = '{!Contact.Id}'; objC.Active__c = true; var result = sforce.connection.update([objC]); window.location.reload(); }