Ajax (1) Apex Class (12) Apex Trigger (2) Community (2) Home Page (1) HTML (4) Integration (3) JS (7) KB (1) Label (1) Licenses (1) Listing (1) Log (1) OOPs (5) Sharing (1) Static Resource (1) Test Class (3) URI (1) Visualforce (10)

Friday, 17 April 2015

Custom Lookup Salesforce

<apex:page standardController="Contact" extensions="MyCustomLookupController" id="Page" tabstyle="Contact">      <script type="text/javascript">     function openLookup(baseURL, width, modified, searchParam){      var originalbaseURL = baseURL;      var originalwidth = width;      var originalmodified = modified;      var originalsearchParam = searchParam;  alert(modified+'hello'+baseURL);      var lookupType = baseURL.substr(baseURL.length-3, 3);      if (modified == '1') baseURL = baseURL + searchParam;        var isCustomLookup = false;        // Following "001" is the lookup type for Account object so change this as per your standard or custom object      if(lookupType == "001"){          var urlArr = baseURL.split("&");        var txtId = '';        if(urlArr.length > 2) {          urlArr = urlArr[1].split('=');          txtId = urlArr[1];        }          // Following is the url of Custom Lookup page. You need to change that accordingly        baseURL = "/apex/CustomAccountLookup?txt=" + txtId;          // Following is the id of apex:form control "myForm". You need to change that accordingly        baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");        if (modified == '1') {          baseURL = baseURL + "&lksearch=" + searchParam;        }          // Following is the ID of inputField that is the lookup to be customized as custom lookup        if(txtId.indexOf('Account') > -1 ){          isCustomLookup = true;        }      }          if(isCustomLookup == true){        openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);      }      else {        if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;        openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);      }     }  </script>    <apex:sectionHeader title="Demo"  subtitle="Custom Lookup" />      <apex:form id="myForm">        <apex:PageBlock id="PageBlock">          <apex:pageBlockButtons >      <apex:commandButton action="{!Save}" value="Save"/>      </apex:pageBlockButtons>            <apex:pageBlockSection columns="1" title="Custom Lookup">        <apex:inputField value="{!Contact.LastName}"/>          <apex:inputField id="Account" value="{!contact.AccountId}"  />          <apex:inputField id="owner" value="{!contact.HR_Manager__c}"  />        </apex:pageBlockSection>      </apex:PageBlock>    </apex:form>    </apex:page>  ===========================
<apex:page controller="CustomAccountLookupController"      title="Search"     showHeader="false"     sideBar="false"     tabStyle="Account"     id="pg">      <apex:form >    <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">      <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">          <!-- SEARCH TAB -->        <apex:tab label="Search" name="tab1" id="tabOne">            <apex:actionRegion >              <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;">              <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/>              <apex:inputText id="txtSearch" value="{!searchString}" />                <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span>            </apex:outputPanel>              <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">              <apex:pageBlock id="searchResults">                 <apex:pageBlockTable value="{!results}" var="a" id="tblResults">                  <apex:column >                    <apex:facet name="header">                      <apex:outputPanel >Name</apex:outputPanel>                    </apex:facet>                     <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>                       </apex:column>                </apex:pageBlockTable>              </apex:pageBlock>            </apex:outputPanel>          </apex:actionRegion>          </apex:tab>          <!-- NEW ACCOUNT TAB -->       <!-- <apex:tab label="New Account" name="tab2" id="tabTwo">            <apex:pageBlock id="newAccount" title="New Account" >              <apex:pageBlockButtons >              <apex:commandButton action="{!saveAccount}" value="Save"/>            </apex:pageBlockButtons>            <apex:pageMessages />              <apex:pageBlockSection columns="2">              <apex:repeat value="{!$ObjectType.Account.FieldSets.CustomAccountLookup}" var="f">                <apex:inputField value="{!Account[f]}"/>              </apex:repeat>            </apex:pageBlockSection>           </apex:pageBlock>          </apex:tab>-->      </apex:tabPanel>    </apex:outputPanel>    </apex:form>  </apex:page>
======================
public with sharing class MyCustomLookupController {
 private ApexPages.StandardController con; 
 public Contact contact {get;set;}
    public MyCustomLookupController(ApexPages.StandardController controller) {
    con=controller;
    contact = new Contact();
    }


  

  public MyCustomLookupController() {
    
  }
  
  public PageReference Save()
    {
   // con.save();
    ApexPages.StandardController c=new ApexPages.StandardController(contact );
    c.save();
    
    PageReference goTothis=new PageReference('/'+c.getId());
    goTothis.setRedirect(true);
    return goTothis;
    }
    

}
===============
public with sharing class CustomAccountLookupController {

  public Account account {get;set;} // new account to create
  public List<Account> results{get;set;} // search results
  public string searchString{get;set;} // search keyword

  public CustomAccountLookupController() {
    account = new Account();
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('krishna');
    runSearch();  
  }

  // performs the keyword search
  public PageReference search() {
    runSearch();
    return null;
  }

  // prepare the query and issue the search command
  private void runSearch() {
    // TODO prepare query string for complex serarches & prevent injections
    results = performSearch(searchString);               
  } 

  // run the search and return the records found. 
  private List<Account> performSearch(string searchString) {

    String soql = 'select id, name from account ';
    if(searchString != '' && searchString != null)
      soql = soql +  ' where name LIKE \'%' + searchString +'%\'';
    soql = soql + ' limit 25';
    System.debug(soql);
    return database.query(soql); 

  }

  // save the new account record
  public PageReference saveAccount() {
    insert account;
    // reset the account
    account = new Account();
    return null;
  }

  // used by the visualforce page to send the link to the right dom element
  public string getFormTag() {
    return System.currentPageReference().getParameters().get('frm');
  }

  // used by the visualforce page to send the link to the right dom element for the text box
  public string getTextBox() {
    return System.currentPageReference().getParameters().get('txt');
  }

}

Thursday, 9 April 2015

Wrapper Class Sorting

public class WrapperClass implements Comparable {

    public Contact idm;
    public String name;
    public String phone;
    
    // Constructor
    public WrapperClass (Contact i, String n, String p) {
        idm = i;
        name = n;
        phone = p;
    }
    
    // Implement the compareTo() method
    public  Integer compareTo(Object compareTo) {
        WrapperClass  compareToWarp = (WrapperClass)compareTo;
        if (idm.lastname == compareToWarp.idm.lastname) return 0;
        if (idm.lastname > compareToWarp.idm.lastname) return 1;
        return -1;        
    }
}

-----------------------------
public class WrapperSorting
{
  
  public WrapperSorting()
  {
  List<WrapperClass> wrapList=new List<WrapperClass>();
        wrapList.add(new WrapperClass(new Contact(lastname='jo jo'),'Joe Smith', '4155551212'));
        wrapList.add(new WrapperClass(new Contact(lastname='Zo jo'),'J. Smith', '4155551212'));
        wrapList.add(new WrapperClass(new Contact(lastname='Ko jo'),'Caragh Smith', '4155551000'));
        wrapList.add(new WrapperClass(new Contact(lastname='Po jo'),'Mario Ruiz', '4155551099'));
        wrapList.sort();
        for(WrapperClass obj:wrapList)
        {
         System.debug('Test='+obj);
        }
  }


}

Tuesday, 3 March 2015

Import stylesheet

A.rar. = extract>>>> A.css

<apex:stylesheet value="{!URL($Resource.A,'A.css')"/>

It will work.
But if A.rar =extract>>>  A.B.C.CSS ,A.D.CSS

Code will not work.

In this condition A.zip will work

Monday, 2 March 2015

About Code Coverage

1. Go to Setup
2. Open the Apex Test Execution in Develop.
3. Click on the Options Button and Uncheck the Option: Store Only Aggregated Code Coverage and save it.
4. Please try to test it and let me know if you still face any issues.

Monday, 23 February 2015

Enabling Super User Access in Communities


Enabling Super User Access in Communities | Salesforce

Enabling Super User Access in Communities

Enable super user access so that partner users in communities can access additional records and data.
Available in: EnterprisePerformanceUnlimited, and Developer Editions

User Permissions Needed
To enable Super User Access:“Customize Application”

If your community is set up with Partner Community user licenses, this setting applies. You can also grant super user access to users with Customer Community Plus licenses. For more information, see Grant Super User Access to Customer Users in Your Community.

Granting super user access to external users in your community lets them access additional data and records, regardless of sharing rules and organization-wide defaults. Super users have access to data owned by other partner users belonging to the same account who have the same role or a role below them in the role hierarchy. Super user access applies to cases, leads, custom objects, and opportunities only, but external users have access to these objects only if you exposed them using profiles or sharing and added the tabs to the community during setup.

  1. Click Customize | Communities | Settings.
  2. Select Enable Partner Super User Access.
  3. Click Save.

You can now assign super user access.

To disable super user access, deselect Enable Partner Super User Access. If you re-enable this feature, all users who were assigned super user access before the feature was disabled will automatically get super user access again.



Sunday, 22 February 2015

Hiding Dropdown Values using javascript on community

Create Custom link Javacript:

{!REQUIRESCRIPT("/communityName/resource/1424668417000/krrish")}

Uploaded static resource:
Name: krrish.js
Code:
setTimeout(function(){
var optionDrop = document.getElementById("00N40000002IC8J");
for (i = 0; i < optionDrop.options.length; i++) {
  if(optionDrop[i].value=='Actional' || optionDrop[i].value=='DataXtend SI'|| optionDrop[i].value=='Savvion'||optionDrop[i].value=='Sonic'||optionDrop[i].value=='DCM'||optionDrop[i].value=='POS'||optionDrop[i].value=='ObjectStore'||optionDrop[i].value=='Other'||optionDrop[i].value=='GCE'||optionDrop[i].value=='CIS'||optionDrop[i].value=='EDI'||optionDrop[i].value=='Hosting Services')
    {
   optionDrop[i].style.display= "none";
   }
}},1000);

Monday, 16 February 2015

How do I add myself as a member of a Community if the Manage Link is missing?

How do I add myself as a member of a Community if the Manage Link is missing?


Knowledge Article Number: 000212095 


Description
In the Spring '15 Release it is now required that your profile be listed as a member of the Community in order to Manage it. If your profile is not listed as a Member then the new Manage Link will not be visible. The following walkthrough shows you how to add your profile back into the Community using the Apex Data Loader tool. 


Resolution
CREATE THE CSV FILE FOR INSERT:

Step 1: Gather your ParentID (Profile) and NetworkID (Community). The following Screen shots demonstrate how to gather this. 

Img 1: Profile ID can be copied from the URL of the Profile detail page.

User-added image

Img 2: NetworkID can be gathered by right clicking on the URL for the Community in the All Communities page in setup. Select Inspect Element and it should give you a console view below the page with the NetworkID highlighted.

User-added image

2. Create a .csv using a program such as Microsoft Excel and include the following Columns:

NETWORKID
PARENTID

3. Input the ID's that you gathered from Step 1 and add them to your csv file. Please see the following screen capture:

Img 3: Spreadsheet showing the correct formatting.

CSV Format

4. Save your file to your computer.

INSERT USING DATA LOADER

1. Download and install the Data Loader tool. Please see the following help article on how to do this:

https://help.salesforce.com/HTViewSolution?id=000005247&language=en_US

2. Open Data Loader and then click on Insert which takes you to the login screen. Login using your Salesforce username and password. See Following Image:

Img 4: Data Loader Login.

User-added image

3. After you receive the Login completed successfully message click next. You should now be at the "Select Salesforce object" page. Click the checkbox next to "Show all Salesforce objects" and Select Network Member Group from the picklist.

4. On the same page Click Browse to add the file location of the CSV file you just saved to your computer. Click Next once you have done this.

5. You will be presented with a Data Selection window showing how many records will be updated. See the following:

Img 5: Records to be updated.

User-added image

6. Click OK. You should now be on the Mapping portion of the process. Click Create or Edit a Map.

7 Click Auto-Match Fields to Columns and click OK.

8. Click Next.

9. Final step is to specify where to save the Success and Error files when the process completes. Click Browse to do this and click Finish.

Now check the All Communities page in setup to confirm that you now see the "Manage" link on the row of the affected Community.