Posts

Convert String to integer

Integer x = 6; String y = '4'; // y is the String Type integer value. x = integer.valueof(y); // y is convert in integer and put value in x which is integer type. system.assertEquals(4,x); System.debug(x); Example : String num1 ='50'; String num2 = '30'; String num3 = num1 +num2 ; // you get 5030 because we are not convert string to integer system.debug(num3) ; Integer num4 = integer.valueof(num1) + integer.valueof(num2) ; // you get 80 because we convert them in integer system.debug(num4) ;

Insert a Record to an object in salesforce

 Account acc = new  Account(); acc.Name = 'Test Account'; Insert acc; syntax- objectApiName obj = objectApiName(); obj.fieldapiName = yourValue; Insert obj; Example-  objectApiName= Account,Contact,Broker__c obj= acc for account , con for contact (anything you write here ) fieldapiName= required field name and all field which value you want to insert( Set mandatory fields if required .) Example = Contact con=new Contact(); con.lastName='Test contact'; insert con; if any validation  are activated then you put value according to your  validation  else it will give you error .

Email Send through apex class

public class singleEmailSend {     // Public method     public static void SingleMail(String address, String subject, String body) {         // Create an email message object         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();         String[] sendingTo = new String[]{address};          mail.setToAddresses(sendingTo);         mail.setSubject(subject);         mail.setPlainTextBody(body);         //message sending       Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});      } }