• Sri_C
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 0
    Replies
Hi All,
Need urgent help with one of the required in our project, please help me..
In a pageblocktable I have 3 rows and 4 fields.
In a record, while adding any value in any of the field then remaining all fields should get mandatory in that particular row only..
We have a constraint in using the JQuery, need solution with the JS only.

Adding VF and Apex class for reference.
Apex Class:

public class D_RequiredFielddemo {
    Public list<contact> contList {get;set;}
    Public boolean depReq{get;set;}
    public boolean titReq{get;set;}
    public boolean selected{get;set;}
    //public integer rowcount{get;set;}
    
    public D_RequiredFielddemo(){
        contList =[select lastName, Department,Title from contact where lastName like: 'C'];
        system.debug(contList);
        depReq= false;
        titReq=false;
    }
    
    public void setRequiredflag(){
        if(depReq==true){
            depReq=false;
        }else depReq=true;
        if(titReq ==true){
            titReq=false;
        }else titReq=true;
        
    }
    
}
 
VF Page:

<apex:page controller="D_RequiredFielddemo" >

<script type="text/javascript">
    /*    function setflag(i){
        //alert(i);
        var str =i.substring(0,i.lastIndexOf(":")+1);
        //alert("my alert"+str);
        var DepId = str+'Dep';
        //alert('Original Value' + i +' Modified Value'+ DepId);
        var TitId= str+'Tit';
        //alert("title id"+TitId);
        
        document.getElementById(DepId).disabled=true;
        document.getElementById(TitId).disabled=true;
    }
    */
    function setflagvalue(){
        alert('hi');
        
    }

</script>    
    <apex:form >
        <apex:actionFunction action="{!setRequiredflag}" name="setflagvalue" reRender="Dep" />
        <apex:variable var="rowcount" value="{!0}" />
        <apex:pageBlock >
            <apex:pageBlockTable value="{!contList}" var="con"> 
                <apex:column >{!rowcount} <apex:variable var="rowcount" value="{!rowcount+1}" /></apex:column> 
                <!--<apex:column > <apex:inputfield value="{!con.Lastname}"    /> </apex:column>-->
                <apex:column ><apex:inputfield id="Dep" value="{!con.department}" onblur="setflagvalue()" required="{!depReq}"/></apex:column>
                <apex:column ><apex:inputfield id="Tit" value="{!con.Title}" onblur="setflagvalue('{!$Component.Dep}','{!$Component.Tit}');" required="{!TitReq}"/></apex:column>
                
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
bloc
  • September 03, 2015
  • Like
  • 0
Dear All,

Im new to SFDC and this is my first post on this community, hope everybody is doing good. I need a help with webservice.

Objective of this program is : It will fetch the records from another organization based on the Objects and fields which we select. Im able to connect to other organization and select the object and fields, but when trying to the fetch the records based on my filter getting following error:

Illegal value for primitive.

Any help on this would be great. Many thanks in advance.

Srikanth.

Here is the class:

public class sfTosf

{

    public String userName {get;set;} 
    public String passWord {get;set;}
    public String securityToken {get;set;}
    public String objectName {get;set;}
    public String[] objNames = new String[]{'None'};
    public List<String> fieldNames = new List<String>();
    public List<String> availableFieldNames = new List<String>();
    public sobjectPartnerSoapSforceCom.sObject_x[] values;
    public List<String> output {get; set;}
    public integer i {get;set;}
    public integer j = 0;
     
    /* String array for select box(Fields) */
    String[] selectedFields = new String[]{};
    String[] checkedFields = new String[]{};
    public partnerSoapSforceCom.Soap con = new partnerSoapSforceCom.Soap();

    public void login()
    {
        if(checkLogin())
        {
            retrieveObjects();
        }
    }

    public boolean checkLogin()
    {
        try
        {                               
            partnerSoapSforceCom.LoginResult loginResult = con.login(username, (password+securityToken));                 
            con.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();     
            con.endpoint_x =loginResult.ServerUrl;     
            con.Sessionheader.sessionid = loginResult.sessionid;
        }
        catch(Exception e)
        {
        }
        return true;
     }
  
     /* Retrieving all the objects */
     public void retrieveObjects()
     {
         if(checkLogin())
         {
             partnerSoapSforceCom.DescribeGlobalresult sobjectResults = con.describeGlobal();
             partnerSoapSforceCom.DescribeGlobalSObjectResult[] objects = sobjectResults.sobjects;      
             for(partnerSoapSforceCom.DescribeGlobalSObjectResult tmpRes:objects)
             {
                 objNames.add(tmpRes.Name);
             }
         }
     }

     /* Getting the selected object name */
     public String getobjectName()  
     {   
         return objectName; 
     }     

     public void setobjectName(String obj)  
     {   
         this.objectName = objectName;  
     }

     public List<SelectOption> getobjectNames() 
     {       
         List<SelectOption> options = new List<SelectOption>();

         for(String temp:objNames)
         {  
         options.add(new SelectOption(temp,temp));
         }   
         return options; 
     }

     public void showFields()
     {
         if(checkLogin())
         {
             partnerSoapSforceCom.DescribeSObjectResult descObjRes = con.describeSObject(objectName);
             partnerSoapSforceCom.Field[] fields = descObjRes.Fields;
             for(partnerSoapSforceCom.Field tmpRes:fields)
             {
                 fieldNames.add(tmpRes.Name);             
             }                  
         }      
     }

     /* Getting the all the field names */

     public List<String> getselectedFields()  
     {   
         return selectedFields; 
     }     

     public void setselectedFields(List<String> selectedFields)  
     {   
         this.selectedFields = selectedFields; 
     }

     public List<SelectOption> getfields() 
     {       
         List<SelectOption> options = new List<SelectOption>();
         fieldNames.sort();

         for(String temp:fieldNames)
         {  
         options.add(new SelectOption(temp,temp));
         }   

         return options; 
     }

     /* Getting the all the field names */

     public List<String> getcheckedFields()  
     {   
         return checkedFields; 
     }     

     public void setcheckedFields(List<String> checkedFields)  
     {   
         this.checkedFields = checkedFields; 
     }

     public List<SelectOption> getfieldsAvailable() 
     {       
         availableFieldNames.sort();
         List<SelectOption> options = new List<SelectOption>();

         for(String temp:availableFieldNames)
         {  
             options.add(new SelectOption(temp,temp));
         }   

         return options; 
     }

     public void addFields()
     {
         for(String tmp:selectedFields)
         {
             availableFieldNames.add(tmp);

             for(i = 0; i<fieldNames.size(); i++)
             {
                if(fieldNames[i] == tmp)
                 {
                     fieldNames.remove(i);
                     break;
                 }
             }                       
         }
     } 

     public void removeFields()
     {
         integer i;

         for(String tmp:checkedFields)
         {
             fieldNames.add(tmp);

             for(i = 0; i<availableFieldNames.size(); i++)
             {
                 if(availableFieldNames[i] == tmp)
                 {
                     availableFieldNames.remove(i);
                     break;
                 }
             }                       
         }
     }

     public void fetch()
     {
         if(checkLogin())
         {
             integer availableFieldNamesLen = availableFieldNames.size();
             String fieldsToQuery = '';

             for(String temp:availableFieldNames)
             {
                 if(j != (availableFieldNameslen - 1))
                 {
                     fieldsToQuery = fieldsToQuery + temp + ',';
                 }
                 else
                 {
                     fieldsToQuery = fieldsToQuery + temp;
                 }              

                 j = j +1;
             }

             String sql = 'SELECT ' + fieldsToQuery + ' FROM ' + objectName; 
            
              System.debug('---Sql Statement---'+ sql);       


             /*-----------------------------------
             Login via SOAP/XML web service api
            -----------------------------------*/
            HttpRequest request = new HttpRequest();
            request.setEndpoint('https://www.salesforce.com/services/Soap/u/22.0');
            request.setMethod('POST');
            request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
            request.setHeader('SOAPAction', '""');

            /*not escaping username and password because we're setting those variables above
            in other words, this line "trusts" the lines above
            if username and password were sourced elsewhere, they'd need to be escaped below*/

            request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + passWord + securityToken + '</password></login></Body></Envelope>');
            Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement()
              .getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/')
              .getChildElement('loginResponse', 'urn:partner.soap.sforce.com')
              .getChildElement('result', 'urn:partner.soap.sforce.com');
 
            /*-------------------------------
             Grab session id and server url
            --------------------------------*/

            final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0];
            final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText();

            /*----------------------------------
             Load first 20 accounts via REST API
            ---------------------------------*/

            final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/v22.0/query/');

            theUrl.getParameters().put('q',sql);
            request = new HttpRequest();
            request.setEndpoint(theUrl.getUrl());
            request.setMethod('GET');
            request.setHeader('Authorization', 'OAuth ' + SESSION_ID);

            String body = (new Http()).send(request).getBody();

            JSONParser parser = JSON.createParser(body);

            do
            {
                parser.nextToken();
            }
            while(parser.hasCurrentToken() && !'records'.equals(parser.getCurrentName()));

            parser.nextToken();
 
            List<String> tmpOutput = (List<String>) parser.readValueAs(List<String>.class);
            //output = tmpOutput;                 

            List<String> tempoutput = new List<String>();
            for(String tmp:tmpOutput)
            {
                if(tmp != null)
                {
                    if(!tmp.contains('attributes') && !tmp.contains('type') && !tmp.startsWith('/services/data/v22.0') && !tmp.contains('url') && tmp != objectName && !tmp.contains('{') && !tmp.contains('}'))
                    {
                        tempoutput.add(tmp);
                    }
                }
            }
            output = tempoutput;
        }
     }
  • February 17, 2014
  • Like
  • 1

Hi,

 

Can you please give me the code to show video files on my menu page.

 

Thanks in advance,

Sricloud

  • October 09, 2012
  • Like
  • 0
Dear All,

Im new to SFDC and this is my first post on this community, hope everybody is doing good. I need a help with webservice.

Objective of this program is : It will fetch the records from another organization based on the Objects and fields which we select. Im able to connect to other organization and select the object and fields, but when trying to the fetch the records based on my filter getting following error:

Illegal value for primitive.

Any help on this would be great. Many thanks in advance.

Srikanth.

Here is the class:

public class sfTosf

{

    public String userName {get;set;} 
    public String passWord {get;set;}
    public String securityToken {get;set;}
    public String objectName {get;set;}
    public String[] objNames = new String[]{'None'};
    public List<String> fieldNames = new List<String>();
    public List<String> availableFieldNames = new List<String>();
    public sobjectPartnerSoapSforceCom.sObject_x[] values;
    public List<String> output {get; set;}
    public integer i {get;set;}
    public integer j = 0;
     
    /* String array for select box(Fields) */
    String[] selectedFields = new String[]{};
    String[] checkedFields = new String[]{};
    public partnerSoapSforceCom.Soap con = new partnerSoapSforceCom.Soap();

    public void login()
    {
        if(checkLogin())
        {
            retrieveObjects();
        }
    }

    public boolean checkLogin()
    {
        try
        {                               
            partnerSoapSforceCom.LoginResult loginResult = con.login(username, (password+securityToken));                 
            con.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();     
            con.endpoint_x =loginResult.ServerUrl;     
            con.Sessionheader.sessionid = loginResult.sessionid;
        }
        catch(Exception e)
        {
        }
        return true;
     }
  
     /* Retrieving all the objects */
     public void retrieveObjects()
     {
         if(checkLogin())
         {
             partnerSoapSforceCom.DescribeGlobalresult sobjectResults = con.describeGlobal();
             partnerSoapSforceCom.DescribeGlobalSObjectResult[] objects = sobjectResults.sobjects;      
             for(partnerSoapSforceCom.DescribeGlobalSObjectResult tmpRes:objects)
             {
                 objNames.add(tmpRes.Name);
             }
         }
     }

     /* Getting the selected object name */
     public String getobjectName()  
     {   
         return objectName; 
     }     

     public void setobjectName(String obj)  
     {   
         this.objectName = objectName;  
     }

     public List<SelectOption> getobjectNames() 
     {       
         List<SelectOption> options = new List<SelectOption>();

         for(String temp:objNames)
         {  
         options.add(new SelectOption(temp,temp));
         }   
         return options; 
     }

     public void showFields()
     {
         if(checkLogin())
         {
             partnerSoapSforceCom.DescribeSObjectResult descObjRes = con.describeSObject(objectName);
             partnerSoapSforceCom.Field[] fields = descObjRes.Fields;
             for(partnerSoapSforceCom.Field tmpRes:fields)
             {
                 fieldNames.add(tmpRes.Name);             
             }                  
         }      
     }

     /* Getting the all the field names */

     public List<String> getselectedFields()  
     {   
         return selectedFields; 
     }     

     public void setselectedFields(List<String> selectedFields)  
     {   
         this.selectedFields = selectedFields; 
     }

     public List<SelectOption> getfields() 
     {       
         List<SelectOption> options = new List<SelectOption>();
         fieldNames.sort();

         for(String temp:fieldNames)
         {  
         options.add(new SelectOption(temp,temp));
         }   

         return options; 
     }

     /* Getting the all the field names */

     public List<String> getcheckedFields()  
     {   
         return checkedFields; 
     }     

     public void setcheckedFields(List<String> checkedFields)  
     {   
         this.checkedFields = checkedFields; 
     }

     public List<SelectOption> getfieldsAvailable() 
     {       
         availableFieldNames.sort();
         List<SelectOption> options = new List<SelectOption>();

         for(String temp:availableFieldNames)
         {  
             options.add(new SelectOption(temp,temp));
         }   

         return options; 
     }

     public void addFields()
     {
         for(String tmp:selectedFields)
         {
             availableFieldNames.add(tmp);

             for(i = 0; i<fieldNames.size(); i++)
             {
                if(fieldNames[i] == tmp)
                 {
                     fieldNames.remove(i);
                     break;
                 }
             }                       
         }
     } 

     public void removeFields()
     {
         integer i;

         for(String tmp:checkedFields)
         {
             fieldNames.add(tmp);

             for(i = 0; i<availableFieldNames.size(); i++)
             {
                 if(availableFieldNames[i] == tmp)
                 {
                     availableFieldNames.remove(i);
                     break;
                 }
             }                       
         }
     }

     public void fetch()
     {
         if(checkLogin())
         {
             integer availableFieldNamesLen = availableFieldNames.size();
             String fieldsToQuery = '';

             for(String temp:availableFieldNames)
             {
                 if(j != (availableFieldNameslen - 1))
                 {
                     fieldsToQuery = fieldsToQuery + temp + ',';
                 }
                 else
                 {
                     fieldsToQuery = fieldsToQuery + temp;
                 }              

                 j = j +1;
             }

             String sql = 'SELECT ' + fieldsToQuery + ' FROM ' + objectName; 
            
              System.debug('---Sql Statement---'+ sql);       


             /*-----------------------------------
             Login via SOAP/XML web service api
            -----------------------------------*/
            HttpRequest request = new HttpRequest();
            request.setEndpoint('https://www.salesforce.com/services/Soap/u/22.0');
            request.setMethod('POST');
            request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
            request.setHeader('SOAPAction', '""');

            /*not escaping username and password because we're setting those variables above
            in other words, this line "trusts" the lines above
            if username and password were sourced elsewhere, they'd need to be escaped below*/

            request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + passWord + securityToken + '</password></login></Body></Envelope>');
            Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement()
              .getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/')
              .getChildElement('loginResponse', 'urn:partner.soap.sforce.com')
              .getChildElement('result', 'urn:partner.soap.sforce.com');
 
            /*-------------------------------
             Grab session id and server url
            --------------------------------*/

            final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0];
            final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText();

            /*----------------------------------
             Load first 20 accounts via REST API
            ---------------------------------*/

            final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/v22.0/query/');

            theUrl.getParameters().put('q',sql);
            request = new HttpRequest();
            request.setEndpoint(theUrl.getUrl());
            request.setMethod('GET');
            request.setHeader('Authorization', 'OAuth ' + SESSION_ID);

            String body = (new Http()).send(request).getBody();

            JSONParser parser = JSON.createParser(body);

            do
            {
                parser.nextToken();
            }
            while(parser.hasCurrentToken() && !'records'.equals(parser.getCurrentName()));

            parser.nextToken();
 
            List<String> tmpOutput = (List<String>) parser.readValueAs(List<String>.class);
            //output = tmpOutput;                 

            List<String> tempoutput = new List<String>();
            for(String tmp:tmpOutput)
            {
                if(tmp != null)
                {
                    if(!tmp.contains('attributes') && !tmp.contains('type') && !tmp.startsWith('/services/data/v22.0') && !tmp.contains('url') && tmp != objectName && !tmp.contains('{') && !tmp.contains('}'))
                    {
                        tempoutput.add(tmp);
                    }
                }
            }
            output = tempoutput;
        }
     }
  • February 17, 2014
  • Like
  • 1