Skip to main content

Posts

How to create a case record from a VF page and attach a particular file to the record?

Below is code snippet for the same. VF Page:- <apex:page controller="creatingcaseAttachment">   <apex:form >       <apex:pageBlock title="Customer Issue">                  <apex:pageBlockSection title="Case Creation ">               <apex:inputField value="{!customerCase.accountid}"/>                 <apex:inputField value="{!customerCase.contactId}"/>                 <apex:inputField value="{!customerCase.Origin}"/>                 <apex:inputField value="{!customerCase.Status}"/>                 <apex:inputField value="{!customerCase.Reason}"/>               <apex:inputField value="{!customerCase.Subject}"/>   ...

How to remove particular key from a map?

This is pretty simple one, One of my friend asked me how to remove a particular key-value pair from a map. Below is code snippet for the same. Hope It will help all. Map<String, String> colorCodes =   new Map<String, String>(); colorCodes.put('Red', 'FF0000'); colorCodes.put('Blue', '0000A0'); colorCodes.put('Blue2', '0000A0'); // If you know the key then just use like below      colorCodes.remove('Blue2'); System.debug('printing=== '+colorCodes); // if you are not sure what about the key or need some manipulation then follow below approach for(String key:colorCodes.keySet().clone()) {     // myMap.get(key), process that value     colorCodes.remove('Blue2'); } System.debug('printing==ater= '+colorCodes);

How to get sandbox name in apex?

As we all know sandbox username looks like " behera@mycompany.com.dev  " dev- is the sandbox name, How can we get it this dynamically ? Use below code :- if( UserInfo.getUserName().substringAfterLast('.com') != null)                     contact.Email = contactInfo.Email+'.'+ UserInfo.getUserName().substringAfterLast('.') ;                 else                     contact.Email = contactInfo.Email; } UserInfo.getUserName().substringAfterLast('.') - will give you sandbox name. UserInfo.getUserName().substringAfterLast('.com') will tell you whether anything is there after " .com ". if not there that means we are in production otherwise in sandbox.  We can also used same method to identify type of org like prod or non prod. There is another approach for this.  Organization org = [select id,IsSandbox fro...

Workaround for COMPILE ERROR: Field is not writeable: Account.IsPartner

As part of my requirement, I had to create an account making isPartner as true, Unfortunately I got this   COMPILE ERROR: Field is not writable: Account.IsPartner  Then I first inserted that account then updated isPartner as true. Account acc = new Account(name = 'Asish'); insert acc; System.debug('Inserted account Ispartner ---'+acc.Ispartner); acc.Ispartner = true; update acc; System.debug('Inserted account---'+acc); For more info on Ispartner field--   https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_account.htm

How to make java script function will execute after the controller method executed?

As we all know java script function will execute first then controller method executes, In some case we need java script method should execute first. Below is the work around for this case. Instead of normal java script we will use on load java script which means when page loads/refresh that java script function will execute. Again it will be problem because each and every time that method will execute. How to avoid this ? We will use a Boolean variable to control execution. public Boolean isJavascriptInvoked {         get {             if (null == this.isJavascriptInvoked ) {                 this.isJavascriptInvoked = false;                         }             return this.isJavascriptInvoked ;         }         set;     } public PageReferen...

How to get document URL dynamically ?

A we all know sales-force host name (na5,or cs20) used to change from sandbox to production and also when SFDC refresh their server. That is why it is always suggested not to use any hard coded link. Below is code snippet to get document URL dynamically.  //method to send document link       public Static String getDocumentRelativeLink(String documentName){         String documentURL= '';         try{             list<Document> doc = [Select id,Name,SystemModStamp From Document Where Name  = :documentName];             ID docIds = doc[0].id;             documentURL ...