Posts

Showing posts from September, 2022

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 .