• darkwater
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello community,

I got the following global classes 
 
/*
* myClass
*/ 
global class myClass{
	webservice static String myWebservice(myTestClass test){
		System.debug('test is '+test);
		return '';
	}
}

/*
* myTestClass
*/ 
global class myTestClass{
	webservice String myString;
	webservice wrapperClass[] wrapperClassList;
}

/*
* wrapperClass
*/ 
global class wrapperClass{
	webservice String myWrapperString;
}

I have created a button on a custom object and my content source is onlick javascript and the following is my javascript code 
 
{!requireScript('/soap/ajax/32.0/connection.js')}
{!requireScript('/soap/ajax/32.0/apex.js')} 
var obj = new sforce.Xml('myTestClass');
obj.myString = 'someString';
obj.wrapperClassList = new Array();
var wrapperClass = new sforce.Xml('wrapperClass');
wrapperClass.myWrapperString = 'wrapperstring';
obj.wrapperClassList.push(wrapperClass);
var myId = sforce.apex.execute('myClass','myWebservice',{test : obj});
document.location = '/someid';

When I click that custom button, it calls mywebservice method and I got the following log 
myTestClass:[wrapperClassList=(wrapperClass:[myWrapperString=null]), myString=someString]
I expect myWrapperString as 'wrapperstring' but for some reason, it shows as null.

How do I pass list of primitive types or sobjects or user defined types to a webservice class as parameters?

Thanks,




 
<apex:page controller="Pagnt" tabStyle="Applicant__c">
   <apex:form >
     <apex:panelGrid id="details" >
       <apex:pageBlock >
          <apex:actionStatus id="pageStatus">
            <apex:facet name="start">
              <apex:outputPanel >
                <img src="{!$Resource.Loader}" width="80" height="20" />
              <apex:outputLabel value="Loading..."/>
              </apex:outputPanel>            
            </apex:facet>
          </apex:actionStatus>
         
       <apex:pageblockTable value="{!applist}" var="app">
            <apex:column value="{!app.Name}"/>
            <apex:column value="{!app.First_Name__c}"/>
            <apex:column value="{!app.Email__c}"/>
            <apex:facet name="footer">Page {!pageNumber} of {!totalPages}</apex:facet> 
            
       </apex:pageblockTable>
      Go To Page &nbsp; <apex:inputText value="{!num}" size="1" />
      <apex:commandButton status="pageStatus" value="GO" action="{!Go}" rerender="details" />
       <apex:pageblockButtons >
         <apex:commandButton status="pageStatus" value="First" rerender="details" action="{!First}" disabled="{!prev}"/>
         <apex:commandButton status="pageStatus" value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
         <apex:commandButton status="pageStatus" value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
         <apex:commandButton status="pageStatus" value="Last" rerender="details" action="{!Last}" disabled="{!nxt}"/>
       </apex:pageblockButtons>
      
      </apex:pageBlock>
    </apex:panelGrid>
  </apex:form>
</apex:page>

And My Apex Code
 
public with sharing class Pagnt {

    public void Go() 
    {
        
     x = num ;
         
    }

    public Integer num { get; set; }
    
    public Integer x {get; set;}

    public Integer getPageNumber() {
    
       x = offsetsize/LimitSize +1 ;
       
       return x;
   }
    
   public Integer getTotalPages() 
   {
      if (math.mod(totalRecs, Limitsize) > 0) 
      {
         return totalRecs/LimitSize + 1;
         
      } 
      else 
      {
         return (totalRecs/LimitSize);
      }
   }

     public integer totalRecs = 0;
     public integer OffsetSize = 0;
     public integer LimitSize= 5;
     
     public Pagnt()
     {
           totalRecs = [select count() from Applicant__c];
           
           
     }
        
     public List<Applicant__c> getapplist()
     {
          
           List<Applicant__C> app = Database.Query('SELECT Name, first_Name__C, Email__C  FROM Applicant__C ORDER BY createddate ASC NULLS LAST  LIMIT :LimitSize OFFSET :OffsetSize');
           System.debug('Values are ' + app);
           return app;
     }
        
    public void First(){
           
        OffsetSize = 0;
      }
    
    public void previous(){
           
        OffsetSize = OffsetSize - LimitSize;
      }
      
    public void next(){
           
        OffsetSize = OffsetSize + LimitSize;
      }
      
    public void Last(){
           
       OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
       
      }
    public boolean getprev()
        {
          if(OffsetSize == 0)
          return true;
          else
          return false;
        }
    public boolean getnxt()
       {
          if((OffsetSize + LimitSize) > totalRecs)
          return true;
          else
          return false;
       }
}

 
Hi,

I am trying to perform dynamic search with sosl but gettig 0 rows.
For same query it is returning 4 rows on workbench.
here is the code snippet for refernce:
list<String>lstNames = new list<String>{'Brain-Prick@gmail.com','Dorsy.Young@coe.com', 'nj-sf@dev.com'};
	String searchquery='FIND {'+ getNames(lstNames) +'} IN ALL FIELDS RETURNING Account(Id,Name),Contact(Id,Name), Lead(Id, Name)'; 
 
	public string getNames(list<string> lstNames){
        String nameList ='';
        for(String name:lstNames){
            //escape hyphen
            if(name.indexof('-')>=0){
                name = name.replace('-', '\\-');
            }
            nameList = nameList + name + ' OR ';
        }
        
        nameList = nameList.substringBeforeLast('OR').trim();
        
        return nameList;
    }

Thanks,
N.J