• Rahul_Salesforce
  • NEWBIE
  • 10 Points
  • Member since 2014
  • Salesforce developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Hi I am working on a jstree implmentation using Javascript and forcetk library(Rest based).
Here is the code I have found from github which I am trying to use.

Component ::
<apex:component >
    
    <apex:attribute name="objectType" description="Used for the REST Query" type="String" required="true"/>
    <apex:attribute name="parentObjectName" description="Used for the REST Query" type="String" required="true"/>
    <apex:attribute name="fieldToQuery" description="Child field Name" type="String" required="true"/>
    <apex:attribute name="parentId" description="The inital id of the parent." type="String" required="true"/>
    <apex:attribute name="objectPluralLabel" description="The plural label." type="String" required="true"/>
    
    
    <apex:includeScript value="{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/_lib/jquery.js')}"  />
    <apex:includeScript value="{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/forcetk.js')}"  />
    <apex:includeScript value="{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/_lib/jquery.cookie.js')}"  />
    <apex:includeScript value="{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/_lib/jquery.hotkeys.js')}"  />
    <apex:includeScript value="{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/jquery.jstree.js')}"  />
    
    
    <div id="tree2"></div>
    <div id="tree"></div>
    <div id="dbg"></div>
    
    <script type="text/javascript">
       
        //////////////////////////////////////////////////
        //
        // VARS
        //
        //////////////////////////////////////////////////
        
        var dbg = false;    
        var objectToQuery = '{!objectType}';
        var parentId = '{!parentId}';  
        var fieldToQuery = '{!fieldToQuery}';

        var pluralLabel = "{!objectPluralLabel}";
        
        //////////////////////////////////////////////////
        //
        // Get a reference to jQuery that we can work with
        //
        //////////////////////////////////////////////////
        
        $j = jQuery.noConflict();
        
        ///////////////////////////////////////
        //
        // Load the themes
        //
        ///////////////////////////////////////
        
        //$j.jstree._themes = "{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/themes/')}";
        
        ///////////////////////////////////////
        //
        // Get an instance of the REST API client
        //
        ///////////////////////////////////////
        
        var client = new forcetk.Client('{!$Api.Session_ID}');
    
        //////////////////////////////////////////////////
        //
        // Instantiate the inital jsTree
        //
        /////////////////////////////////////////////////
        alert('Rahul'+'{!parentObjectName}');
        $j("#tree").jstree({ 
                "plugins" : [ "themes", "json_data", "ui", "crrm", "cookies", "dnd", "search", "types", "hotkeys", "contextmenu" ],
        
                "json_data" : {
                    "data" : [
                        { 
                            "data" : "{!parentObjectName}",
                            "state": "closed", 
                            "attr" : { "id" : parentId }
                         
                        },
                    ]
                },
                "types" : {

                    "max_depth" : -2,
                    "max_children" : -2,
                    "type_attr" : "rel",
                    "valid_children" : [ "default" ],
                
                    ////////////////////////////////
                    // Define the themes
                    ////////////////////////////////
                    
                    "types" : {
                
                            "children" : {
                                "icon" : { 
                                    "image" : "{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/folder.jpg')}" 
                                },
                                "valid_children" : ["noChildren","children" ]
                            },
                            "noChildren" : {
                                "icon" : { 
                                    "image" : "{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/leaf.jpg')}" 
                                },
                                "valid_children" : ["noChildren","children" ]
                            },
                            
                            "default" : {
                                "icon" : { 
                                    "image" : "{!URLFOR($Resource.restJavascript, '/lazy-load-tree-master/source/rest/home.jpg')}" 
                                },
                                "valid_children" : [ "noChildren","children" ]
                            }
                    }
                }
           
                
                
            });
            
    //////////////////////////////////////////////////
    //
    // Add the logic to query if there are children
    //
    /////////////////////////////////////////////////
    
    $j("#tree").bind("open_node.jstree close_node.jstree click", function (e,data) {
            
         //loadNode(parentId);
         
        console.log('SeriousRahul'+data.instance.get_node(data.selected[0]).text);
         //loadNode($j(this).parent().attr("id"));
        if(e.type == 'open_node' && data.args[0].attr("id") != parentId) {
           
            var thisNode = $j('#'+data.args[0].attr("id"));
            
            if(thisNode.find('li').length == 0) {
            
                loadNode(data.args[0].attr("id"));
           
            }
        }
        
        
    })
    
    $j("#tree").delegate("a","click", function (e) {
        
        /// Dont open a window for ultimate parent
        if($j(this).parent().attr("id") != parentId) {
        
            window.open("/" + $j(this).parent().attr("id"),"mywindow","status=1,toolbar=1,location=1,menubar=1,resizable=1,scrollbars=1");

        }
     });
     
    //////////////////////////////////////////////////
    //
    // Load nodes
    //
    /////////////////////////////////////////////////      

    function loadNode(parentIdPassed) {
      
        var query = "SELECT Id," +fieldToQuery +", Name, (Select Id From "+pluralLabel+") FROM " + objectToQuery + " WHERE " +fieldToQuery +" = '" + parentIdPassed + "'";
          alert('Rahul'+query);
        /////////////////////
        /// Debugging
        /////////////////////
        
        if(dbg) {document.getElementById('dbg').innerHTML += "<br/>---<br/> node query - " + query;}
        
        client.query(query,parseNode);
    
    }
    
    function firstNodeLoad() {
        
        var query = "SELECT Id," +fieldToQuery +", Name, (Select Id From "+pluralLabel+") FROM " + objectToQuery + " WHERE " +fieldToQuery +" = '" + parentId + "'";
        
        
        alert('++++' + query);
        /////////////////////
        /// Debugging
        /////////////////////
        
        if(dbg) {document.getElementById('dbg').innerHTML += "<br/>---<br/> firstNodeLoad query - " + query;}
 
        client.query(query,parseNode);
        
    }
      
     
    //////////////////////////////////////////////////
    //
    //  Parse the REST repsonse
    //
    /////////////////////////////////////////////////
    
    function parseNode(response) {
        
        //system.debug('RahulResponseLength'+response);
        
        for(var i=0; i<response.records.length; i++) {
            
            var hasChildren = false;
            
            if(response.records[i][pluralLabel]!= null) {
                
                hasChildren = true;
            }
            
            addNode(response.records[i][fieldToQuery],response.records[i].Name,response.records[i].Id,hasChildren);
            
        }
            
    }   
        
    //////////////////////////////////////////////////
    //
    // Add each node
    //
    /////////////////////////////////////////////////       
    
    function addNode(localParentId,nodeName,nodeId,hasChildren) {
            
            ////////////////////////////////////////////
            //
            // Create a new node on the tree
            //
            ////////////////////////////////////////////
            alert('Rahul'+nodeName+nodeId);
            
            if(hasChildren) {
            
                /// If it has children we load the node a little differently
                
                $j("#tree").jstree("create", $j("#"+localParentId), "inside",  { "data" : nodeName ,"state" : "closed","attr" : { "id" : nodeId,"rel":"children"}},null, true);

                
            } else {
            
                $j("#tree").jstree("create", $j("#"+localParentId), "inside",  { "data" : nodeName ,"state" : "leaf","attr" : { "id" : nodeId,"rel":"noChildren"}},null, true);
            
            }
            
    }
    
    window.onload = firstNodeLoad;
  
    </script>
    

</apex:component>
when I am making the JSON request the data is comming properly but not sure why it is not available in the below function from above component. when I am trying to print data it is coming as "undefined".Any help would be appreciated.
$j("#tree").bind("open_node.jstree close_node.jstree click", function (e,data) {
            
         //loadNode(parentId);
         
        console.log('SeriousRahul'+data.instance.get_node(data.selected[0]).text);
         //loadNode($j(this).parent().attr("id"));
        if(e.type == 'open_node' && data.args[0].attr("id") != parentId) {
           
            var thisNode = $j('#'+data.args[0].attr("id"));
            
            if(thisNode.find('li').length == 0) {
            
                loadNode(data.args[0].attr("id"));
           
            }
        }
 
Hi,
We have a requirement where we need to freeze few columns of a pageblocktable/datatable . Basically we want excel like functionality where we can freeze few columns. Any help will be greatly appreciated.

Thank you,
Rahul 
Hi Friends,
Thanks in advance, I am facing problem with Looup field ,I want it should seperate from section, please help me over here .

Note:
1--> I dont want to enter looup field multiple of times insted of that I want it should be header.
2--> Lookup field value is manditory for entire page.

I found issue is in Controller ( public multiadd(ApexPages.StandardController ctlr))

VF page code
<apex:page StandardController="mycontroller__c" extensions="multiadd" id="thePage" sidebar="false">

<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
    </apex:pageBlockButtons>
        
         <table width="100%">                
                <tr width="100%"><th><center>HelpPortal</center></th></tr>                     
                     <tr>
                        <td rowspan="4"></td>
                      </tr>
                      <tr>
                        <td><h1 style="text-align:center;color:blue;">Text1 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text1__c}" style="width:50px;height:20px;"/></h1></td>
                        <td><h1 style="text-align:center;color:blue;">Text2 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text2__c}" style="width:50px;height:20px;"/></h1></td>
                      </tr>
                      <tr>
                        <td><h1 style="text-align:center;color:blue;">Text3 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text3__c}" style="width:130px;height:20px;"/></h1></td>
                        <td><h1 style="text-align:center;color:blue;">Text4 &nbsp;:&nbsp;&nbsp;<apex:inputText value="{!Tour_Plan__c.Text4__c}" style="width:50px;height:20px;"/></h1></td>                        
                      </tr>
                      <tr>
                        <td><h1 style="text-align:center;color:blue;">Text5 &nbsp;&nbsp;&nbsp;
                        <apex:inputText value="{!Tour_Plan__c.DATE_OF_TRAVEL__c}" style="width:50px;height:20px;"/></h1></td>
                        <td></td>                      
                        </tr>
                </table>
        <apex:pageblock id="pb1">              
        <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="16"> 
                
                <apex:panelGrid title="Date" >
                    <apex:facet name="header">Date</apex:facet>
                    <apex:inputfield value="{!e1.acct.Date__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>  
                                                
                <apex:panelGrid title="Unit Cost" >
                    <apex:facet name="header">Text1</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text1__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Nights" >
                    <apex:facet name="header">Text2</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text2__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Twin" >
                    <apex:facet name="header">Text3</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text3__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid title="Tripl" >
                    <apex:facet name="header">Text4</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text4__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                
                <apex:panelGrid >
                    <apex:facet name="header">Text5</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text5__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                
                
                <apex:panelGrid >
                    <apex:facet name="header">Text6</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text6__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                                
                <apex:panelGrid >
                    <apex:facet name="header">Text7</apex:facet>
                    <apex:inputfield value="{!e1.acct.Text7__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Dependency Lookup</apex:facet>
                    <apex:inputfield value="{!e1.acct.CustomName__c}"  style="width:50px;height:20px;"/>
                </apex:panelGrid>
                
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>                 
            </apex:panelgrid>
        </apex:repeat>
    </apex:pageBlock> 
</apex:pageblock>
</apex:form>
</apex:page>
Controller
public class multiadd
{
    
    //will hold the mycontroller__c records to be saved
    public List<mycontroller__c>lstAcct  = new List<mycontroller__c>();
    
    //list of the inner class
    public List<innerClass> lstInner 
    {   get;set;    }
    
    //will indicate the row to be deleted
    public String selectedRowIndex
    {get;set;}  
    
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    //{get;set;}
    
    
    ////save the records by adding the elements in the inner class list to lstAcct,return to the same page
    public PageReference Save()
    {
        PageReference pr = new PageReference('/apex/multiaddSuccessPage');
        
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstAcct.add(lstInner[j].acct);
        } 
        insert lstAcct;
        pr.setRedirect(True);
        return pr;
    }
        
    //add one more row
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    
    /*Begin addMore*/
    public void addMore()
    {
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        
        //add the record to the inner class list
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }/* end addMore*/
    
    /* begin delete */
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }/*End del*/
    
    
    
    /*Constructor*/
    public multiadd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
        
    }/*End Constructor*/
        


    /*Inner Class*/
    public class innerClass
    {       
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        {get;set;}
        
        
        public mycontroller__c acct 
        {get;set;}
        
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);        
            
            /*create a new mycontroller__c*/
            acct = new mycontroller__c();
            
        }/*End Inner class Constructor*/    
    }/*End inner Class*/
}/*End Class*/

Requirement

Note:
1--> I dont want to enter looup field multiple of times insted of that I want it should be header.
2--> Lookup field value is manditory for entire page.

showing Error if Lookup field removed

Error


 
I have ControllerExtension for Account’s child Object. Obj1   Profile A  User UA has permission to CRUD for Account and OBJ1. Profile B  - User UB doesn’t have access to ControllerExtension as well as VF page.  When I login as user UB in developer sandbox, and test through UI, I get insufficient privileges for page using  ControllerExtension. This is as expected.
I have written test class to test this scenario. But it doesn’t give me this error.

But if I use Chatter Free profile to create runAs User , I get the exception in catch part.
Is there way to catch or debug insufficient privilages?

How to write test class to test User Privileges?
@isTest
    public static void testUserAccess(){
        // create test user
         User runUsr =  [select name, id, profileId from User where id = '005j000034BMsou' limit 1];
        //TestExtension.createProfileBUser();
//As this doesn’t work, I am directly retrieving user who as profileB
        System.debug(' runUsr ' + runUsr);
   // This prints me correct user         
        System.runAs(runUsr){
            user rrU = [select name, id, profileId                             from user
                        where id = :UserInfo.getUserId()];
            System.debug('runUsr rru' + runUsr + ' ' + rrU); 
            System.assertEquals(runUsr,rrU) ;              
            //Both above users are matching
            
// Create Account        
            Account account = new Account(name='testAccount');
            insert account;
            // I expect error here but no error
            // Create the controllerExtension and click cancel
            ApexPages.StandardController std =  new ApexPages.StandardController(account);
            CCExtension ctrl;
            PageReference page;
            try{
                ctrl = new CCExtension (std);
                System.debug(' Created ctrl ' + ctrl );
                System.AssertEquals(null,ctrl);
                page = ctrl.save();
            } catch(Exception e){
                System.debug(' CTRL creation Exception e ' + e);
// No error message here too
            }
             System.assertEquals(null, page);
// this passes - is this the way to write the test?
            if(ApexPages.hasMessages()){
                System.debug('There are error messages');
                for(ApexPages.Message msg:ApexPages.getMessages()){
                    System.assert(true, ' Error messages ' +  msg );
                }
            }
            
        }
Hi, 

We have requirement to share one account with multiple users. Please suggest suitable approach to do ?

1. account teams - is account team works fine? is there any limiations use account teams?
2. custom object - admin will upload account code and owner code, write a trigger to share account record?

Thanks 
Hi,

I have scenario that update a custom field(Amount__C) of parent(Account) with sum of all child records (Total_Price) from Child Object(Invoice Line Item).

I have to wirte a trigger for above scenario, if any one have sample code please share it.

Thanks in advance,
Shaik
  • December 21, 2014
  • Like
  • 1