Forum Replies Created

Page 2 of 4
  • Ajit

    Member
    August 11, 2016 at 6:55 am in reply to: What is the use of gethost() method in Salesforce apex?

    Hi Tannu,
    The URL instance method getHost() is used to get the hostname of the Salesforce server that you are using. For instance, if your Salesforce instance is ap1 then you would get the result as "ap1.salesforce.com".

    In case of custom domains, suppose your org has a custom domain "my-dev-org" the method would return "my-dev-org.ap1.my.salesforce.com"

    You can try out the function in anonymous execution block:

    system.debug(URL.getSalesforceBaseUrl().getHost());

  • Ajit

    Member
    August 11, 2016 at 6:53 am in reply to: How can we separate the ID's based on the record type?

    Hey Mohit,

    you will have to create number of sets equal to the record type that you have for eg: if there are two record types then create 2 sets and add values in the set on the basis of record types.

    map<id,String>mapidvsRecTypeId = new map<id,String>();

    for (Account acc : [select id , recordTypeId from Account]){

    mapidvsRecTypeId.put(acc.Id, acc.recordTypeId);

    }

    set<Id>set1 = new set<Id>();

    set<Id>set2 = new set<Id>();

    for(Id accIds : set containing account id's){

    if(mapidvsRecTypeId.get(accIds) = reocrdTypeId1 ){

    set1.add(accIds);

    }

    if(mapidvsRecTypeId.get(accIds) = reocrdTypeId2 ){

    set2.add(accIds);

    }

    }

     

  • Ajit

    Member
    August 10, 2016 at 12:18 pm in reply to: How to display Account Owner name in Visualforce Page?

    Hi Pranav,

     

    Do you have tried this

    <apex:outputfield value=”{! Account.Ownerid}”/>

    set the value of Account.Ownerid in you controller with id of current user in the constructor do let me know if it worked or not

  • Ajit

    Member
    August 10, 2016 at 12:09 pm in reply to: Error in printing series 1, (1+1)^2= 4, (4+1)^2 =25 upto 10 terms.

    Hi Pranav,

    System.debug(n1 + ‘, (‘ + n1 + ‘+’ + n2 + ‘)^’ + n3 + ‘=’ + n4 + ‘ , ‘);

    it is in for loop use it outside of the loop.

  • Ajit

    Member
    August 10, 2016 at 12:02 pm in reply to: Is there any logs for Email Alerts to verify if email was delivered?

    Hi Tanu,

    Go to Setup Logs > Email Logs there you can request for an email log that are being sent from you org will be sent on you email ID.

  • Ajit

    Member
    August 10, 2016 at 11:55 am in reply to: How can we ignore spaces when comparing two values?

    Hi Pranav,

    If you are comparing string then you can use the string methods to delete white spaces from the string

    String s1 = ' Hello Jane ';
    String s2 = 'HelloJane';
    System.assertEquals(s2, s1.deleteWhitespace());

    it will delete all the white spaces.

     

    tring s1 = ' Hello! ';
    String trimmed = s1.trim();
    system.assertEquals('Hello!', trimmed);

    it will remove trailing and leadin white spaces.

  • Ajit

    Member
    May 25, 2016 at 10:28 am in reply to: How can I enable the inline editing on custom vf page?

    Hi Naman,

    This can be done by using a apex tag : enableInlineEditing="true" on the custom vf page.

  • Ajit

    Member
    May 25, 2016 at 9:55 am in reply to: How to get the picklist value in formula fields?

    Hi Naman,

    You can't use picklist values directly as TEXT(field name) , you have to use ISPICKVAL(FieldName)

  • Ajit

    Member
    May 24, 2016 at 10:20 am in reply to: Method to find corresponding value of a key in map?

    HI Ajay,

    You can use this method

    map.get(key); it will return the value stored against this key.

  • Ajit

    Member
    May 24, 2016 at 10:13 am in reply to: How can I get a debug log for the sites guest user/public profile?

    Steps to set the debug logs :

    Setup > Monitoring > Debug log

    where you put the user name put the name of your site, and the log is set for the site guest user.

  • Ajit

    Member
    May 24, 2016 at 10:09 am in reply to: How do you delete a class from production without using an IDE?

    Hi Ravi,

    You can do it by using ANT script

    <?xml version="1.0" encoding="UTF-8"?>
    <Package xmlns="http://soap.sforce.com/2016/04/metadata">
    <fullName>codepkg</fullName>
    <types>
    <members>Test1</members>
    <members>Test2</members>
    <name>ApexClass</name>
    </types>
    <version>36.0</version>
    </Package>
    Run the below script in prompt

    ant undeployCode

  • Hi Piyush,

    Yes you can you have to query out all the recordtypes in your controller, and after that create a select list and pass the list in the select list.

  • Ajit

    Member
    May 24, 2016 at 9:56 am in reply to: How to override the standard page only for specific record Type?

    Hi Piyush,

    You can simply do this by creating multiple page layouts and assign for all the record types and after that crate a vf page using apex detail and after that assign that page to the view button and you are done.

  • Ajit

    Member
    May 24, 2016 at 9:49 am in reply to: Why can't I use a wrapped sObject in an apex:outputField?

    Hi Ravi

    Need to see your code to solve this problem, from your question it is not clear that how you are using the sObject in your wrapper class.

  • Ajit

    Member
    May 24, 2016 at 9:46 am in reply to: Getting error while running SOQL declared as String

    Hey Piyush

    Try this query

    String accountQuery = 'SELECT Id,BillingPostalCode,County_Name__c '+
    'FROM Account WHERE zipCodeLen__c = 9 AND BillingCountry =: '+ Country;

     

  • Ajit

    Member
    May 24, 2016 at 9:42 am in reply to: Is there a way to make the insert not fail if one record fails?

    Hi Ravi

    Yes it is possible, If you use dataBase.insert(list,false) rather then using simple insert.

    One thing also to be noted that if you make the Boolean value to "true" then this insert will also work as the simple insert works.

  • Hey Ravi,

    Its very simple, but need to see your vf page code because if you are using Data table then this can be done but we can do this by using apex:repeat and by using HTML tags.

    <table>
    <tr>
    <apex:repeat value="{!testList}" var="tc" />
    <td>
    <apex:outputText  value="{!tc.test1}"/><br />
    <apex:outputText value="{!tc.test2}"/><br />
    <apex:outputText value="{!tc.test3}"/><br />
    </td>
    </apex:repeat>
    </tr>
    </table>

     

  • Ajit

    Member
    May 24, 2016 at 9:31 am in reply to: How to check a string has only numbers?

    Hi ravi,

    You can use isNumeric() or isNumericSpace() method to find a string is number or not

    String num = '23456789;
    System.assert(num.isNumeric());

    this will check string without space

    String numSpace = '5 4 6 8';
    System.assert(numSpace.isNumericspace());

    this will include spaces also.

  • Ajit

    Member
    April 30, 2016 at 6:29 pm in reply to: How to release the a lock on Apex Class from Scheduled Job

    There is a Known Issue regarding getting rid of the code lock from Scheduling: http://success.salesforce.com/issues_view?id=a1p30000000STwPAAW . See if this is your situation.

  • Ajit

    Member
    April 30, 2016 at 6:28 pm in reply to: How can I specify that a sandbox be created on a specific instance?
  • Ajit

    Member
    April 30, 2016 at 6:24 pm in reply to: Can I change the standard tab styles?

    You cannot change the styles of the standard tabs. You can however set tab-styles via the 'Tab' setup for a custom object or VF tab.

    I've done the JS manipulation with using non-standard controllers and tabs like this before, but it was less than ideal and not very stable.

  • Ajit

    Member
    April 30, 2016 at 6:23 pm in reply to: How can I add @mention when creating a FeedItem via APEX?

    String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();

    String url = salesforceHost + '/services/data/v23.0/chatter/feeds/record/' + RecordId + '/feed-items';

    HttpRequest req = new HttpRequest();

    req.setMethod('POST');
    req.setEndpoint(url);
    req.setHeader('Content-type', 'application/json');
    req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());

    req.setBody('{ "body" : { "messageSegments" : [ { "type": "mention", "id" : "' + UserId + '" }, { "type": "text", "text" : "' + ' ' + chatterAlert + '" } ] } }');
    Http http = new Http();

    HTTPResponse res = http.send(req);

  • Ajit

    Member
    April 30, 2016 at 6:21 pm in reply to: Is it possible to remove/hide the “New” button?

    We use homepage components which analyse the page, and use javascript to remove/add buttons where we have no other choice to do so. But this implies developing with a high dependency on the salesforce html output .. which is not guaranteed to stay unchanged, this is something to strongly consider if you would explore this approach.

    Why do you want to remove the new button ? If there are groups of users who should not make opportunities, you may want to restrict them access through their profile.

    update: For instance, using jquery:

    if (document.location.href.toString().indexOf("/a49/o") != -1) {
    $('input[name=new]').hide();
    }

    You would need to update the Id when migrating code between sandboxes/organisations

  • Ajit

    Member
    April 30, 2016 at 6:19 pm in reply to: How can I create a Chatter Free License user in a test class?

    The license isn't actually connected to the user, but depends on the profile you assign your user. If you create a user with the Chatter Free User profile, the usertype will be set to Chatter free.

    5.0 APEX_CODE,DEBUG
    Execute Anonymous: Profile p = [SELECT id, Name FROM Profile where name = 'Chatter Free User' ].get(0);
    Execute Anonymous:
    Execute Anonymous: User u = new User(firstname= 'Samuel',
    Execute Anonymous: lastname='De Rycke',
    Execute Anonymous: Alias='Samuel',
    Execute Anonymous: email = '[email protected]',
    Execute Anonymous: username= '[email protected]',
    Execute Anonymous: profileId= p.id,
    Execute Anonymous: emailencodingkey='UTF-8',
    Execute Anonymous: languagelocalekey='en_US',
    Execute Anonymous: localesidkey='en_US',
    Execute Anonymous: timezonesidkey='America/Los_Angeles');
    Execute Anonymous: insert u;
    Execute Anonymous:
    Execute Anonymous: u = [select usertype from user where id =:u.id];
    Execute Anonymous:
    Execute Anonymous: system.debug('--------------------------->User.UserType:'+u.usertype);
    13:15:05.040 (40786000)|EXECUTION_STARTED
    13:15:05.040 (40800000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
    13:15:05.769 (769888000)|USER_DEBUG|[17]|DEBUG|--------------------------->User.UserType:CsnOnly
    13:15:05.820 (820554000)|CODE_UNIT_FINISHED|execute_anonymous_apex
    13:15:05.820 (820567000)|EXECUTION_FINISHED

  • I believe it's possible to query for the existence of an Approval Request related to your record, I believe this is via: ProcessInstance. Try checking out:https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_process_example.htm|StartTopic=Content%2Fapex_process_example.htm|SkinName=webhelp

    Additionally, you could write a method to attempt to update the record, and trap the exception message that comes from the record being locked and hide the buttons based on that result!

Page 2 of 4