Skip to main content

Posts

Showing posts from December, 2015

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