• WEN JIE
  • NEWBIE
  • 65 Points
  • Member since 2011

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 48
    Questions
  • 96
    Replies
Hi,

I just working on SSO between Salesforce and third party system. When I test the "SP Initiated" way, I found there is a parameter in http header which named "saml_request_id".

So does anyone kown the generate principle for this parameter? Or where can I get this "saml_request_id"?


Thank you1
Hi,

I have a problem when I developing my VF page.
I have a sobject which has a field, the type for this field is "Rich Text Area". And on my VF page, I use "<apex:inputField>". Then for some reason, I need to get value from this rich text area by js or jquery.
At before, I check the page source, then use the following code to get the content from this text area:
"var internalRequirements = document.getElementById('auditPage:auditForm:auditPageBlock:itnternalRequirements:textAreaDelegate_InternalRequirements__c_frame').contentDocument.body.innerHTML;"

But it can't work anymore now.

So does anyone have good solution for this?


Thank you!
Hi,

I have a custom visualforce page. And I have a pageBlockSection with two contents. One is a <apex:tabPanel>, another one is <apex:inputField>.
In tabPanel, I have four <apex:tab> to display a multi picklist. But the contents in each tab, I use the HTML element not the apex tag.

Then I met the following problem,
We know we can collapse the Salesforce sidebar mannually. If I use the apex tag on VF page, when I collapse or open sidebar, the apex tag can adapt the page size automatically. But if I have HTML elements, they can't do this.

Have a look with screenshot:
The "Internal Requirements" is apex tag. The contents in tab are HTML elements.

When collapse sidebar:
User-added image

When expand sidebar:
User-added image

So does anyone know how to resolve this problem?


Hi,

 

I want to get the "Salesforce.com Certified Administrator"(201) certificate. I have passed DEV 401 before. I want to know whether there have a document for this 201 exam.

 

 

I download the "SGCertifiedAdministrator.pdf" but this is only a simply introduction pdf file. Does salesforce have a detailed ducoment to help us pass the ADM 201 exam?

 

 

Thank you!

Hi, 

 

I use <apex:repeat> in my visualforce email template. And the value for this tag is a list. But actually, I just only want to get one record from this list, maybe first one or last one.

 

So, does anyone know how to achieve this?

 

Thank you!

Hi,

 

I have a compotent display some info for one sobject. And for this component I have a custom controller to select info about this object by record id. I also create an attribute for this component to get record id from template.(I test it works well)

 

Then I create a visualforce email template. I set recipientType as "User" and relatedToType as my sobject. Then invoke that component in <messaging:attachment renderas="pdf">.

 

Then I saw this error message:

Error occurred trying to load the template for preview: List has no rows for assignment to SObject. Please try editing your markup to correct the problem.
 

But when I run my code this template can be invoke and I can get the mail with that pdf attachment.(production a)
And in another production environment I run as a real user (not administrator), I saw the same error.(production b)
Error occurred trying to load the template for preview: List has no rows for assignment to SObject. Please try editing your markup to correct the problem.
 

I think maybe my component custom controll didn't get the record id from template. And I really don't know why code can run in production a but can't work in production b.
 
Thank you!!!
 

Hi,

 

So far I can get a visualforce page content as pdf by pageRef.getContentAsPdf() method.

 

Now I want to get a standard page content and send them as pdf attachment in my mail.

I use the following code:

Audit__c audit = new Audit__c();
audit.Id = auditId;
        
PageReference pageRef = new ApexPages.StandardController(audit).view();
pageRef.s  etRedirect(true);

Blob b = pageRef.getContent();

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachment.pdf');
efa.setContentType('application/pdf');
efa.setBody(b);

But when I try to open this pdf file I get some error as "wasn't correctly decoded".

 

If I use pageRef.getContentAsPdf(), the code can't go through and doesn't have any error info.

 

So does anyone know how to change a standard record view page as a pdf file and send it as attachment?

 

Thank you!!!

 

 

Hi,

 

I need a custom button display on my standard page layout. When I click this button can send mail to some users.

So I create a custom button, and in the "Behavior" field, I choose "Execute JavaScript". Then I try to invoke my remote action to send maill.

 

if(confirm('Is your Distribution list updated ?')){
    alert('send');
    AuditController.saveAudit(auditData , SaveCallBack, {escape:true});
}
else{
    alert('just save');
}

function SaveCallBack(result, event){
    alert(1);
}

 

But it fail. When code go to the ture condition. There is a error tell me AuditController is not defined.

 

So does anyony know how to send mail by a custom button on the standard pagelayout?

 

Thank you!

Hi,

 

I have a custom object as "A__c". And I create a trigger when I update this object record. This trigger will send mail to some users.

 

Then I create an email visualforce template. And let my trigger invoke this template when I send mail.

But I met a problem about the template.

 

I set the recipientType as "User", and relatedToType as my custom object "A__c"

 

<messaging:emailTemplate subject="Assign Audit" recipientType="User" relatedToType="A__c">
<messaging:plainTextEmailBody >
Hello {!recipient.name}

This is {!relatedTo.Name}

</messaging:plainTextEmailBody>
</messaging:emailTemplate>

When I use "Send Test and Verify Merge Fileds",assign an user and an "A" record, I can see the corresponding value display on this mail body.

 

But if I update a record then the trigger run and invoke this template, the {!recipient.name} can get value and display, but {!relatedTo.Name} can't get any value.

 

 

So does anyone meet this problem before? Or whether I have some wrong code at this template.

 

Thank you!

Hi,

 

I have a field as a rich textarea. I use inputField display this field on my vf page. But I don't know how to get the value by js or jquery. And I foung this is an iframe generagte automatically when I check the page source.

 

Does anyone knows this?

 

Thank you!

Hi,

 

I want to know whether the MobileSDK support the offline secure storage for a hybrid app.

If not, does any one has good solution about that?

And how to control the transaction when user update or insert data to salesfore meanwhile the moble device  suddenly offline.

 

Thank you!

Hi,

 

I have a problem about visual force table tag.

I use <apex:datatable> in my visualforce page, and I set a dynamic data set for this table. But now I want to set a fixed value at the first row in this table ,then display other dynamic data.

 

Does anyone know how to achieve this?

 

Thank you!

Hi,

 

I use rest api to do the CRUD with Salesforce data.

But when I do the insert data I met a problem.

My object's Standard Field Name "Name" 's Data Type is "Auto Number".  So I set a value like my auto-number style like "A0002", then I call the endpoint. But I see the following error:

 

Fail to create record on TestPackage11__TestWen__c. Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.

 

Then I change this Data Type as a "Text", the create operate can work successful.

 

So does anyone know how to insert a data when the object's name fields is the auto-number type?

 

Thank you!

Hi,

 

Please have a look with my scenario:

I have an object which has 4 fields. I put these in the filed set as available. Now I want to give access to customer to move it, show it or hide it and manage it on VF page.

 

Can I achieve this by Field Sets function?

 

Thank you!

Hi,

 

I want to know how to get value about this tab on Visualforce page.

 

 

Thank you!

Hi,

 

We have a legacy application, it's a cobol application. And we want to connect Salesforce to it then we can fetch data from that legacy app and display them on Salesforce.com.

 

Does anyone has any suggestion about this?

 

Thank you!

Hi,

 

I'm looking for a test case generation tool which supports our Salesforce.

 

Does anyone can give me some suggestion about this? Or which generation tool you use on Salesforce?

 

Thank you!

Hi,

 

Does anyone know how to create a custom encrypted filed(like password)? And how does Salesforce store it and  retrieve back the details?

 

Thank you!

Hi,

 

I met a problem when I install Force.com IDE in my computer.

I run the "force.com-ide-installer-win32.exe" and my OS is Windows 7.

 

The following is error log:

 

 

!SESSION Thu Aug 09 14:07:29 CST 2012 ------------------------------------------
!ENTRY org.eclipse.equinox.launcher 4 0 2012-08-09 14:07:29.089
!MESSAGE Invalid splash path entry: platform\:/base/plugins/org.eclipse.platform
!SESSION 2012-08-09 14:07:28.808 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_33
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments: -noPulseUpdate
Command-line arguments: -os win32 -ws win32 -arch x86 -noPulseUpdate

!ENTRY org.eclipse.osgi 4 0 2012-08-09 14:08:18.401
!MESSAGE Application error
!STACK 1
org.eclipse.swt.SWTException: Invalid image
at org.eclipse.swt.SWT.error(SWT.java:4083)
at org.eclipse.swt.SWT.error(SWT.java:3998)
at org.eclipse.swt.SWT.error(SWT.java:3969)
at org.eclipse.swt.internal.image.PngChunkReader.readNextChunk(PngChunkReader.java:46)
at org.eclipse.swt.internal.image.PNGFileFormat.readNextChunk(PNGFileFormat.java:89)
at org.eclipse.swt.internal.image.PNGFileFormat.loadFromByteStream(PNGFileFormat.java:75)
at org.eclipse.swt.internal.image.FileFormat.loadFromStream(FileFormat.java:48)
at org.eclipse.swt.internal.image.FileFormat.load(FileFormat.java:84)
at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:130)
at org.eclipse.swt.graphics.ImageDataLoader.load(ImageDataLoader.java:22)
at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:331)
at com.genuitec.pulse2.common.ui.CommonUIActivator.getImage(Unknown Source)
at com.genuitec.pulse2.client.launcher.ui.LauncherUIActivator.getImage(Unknown Source)
at com.genuitec.pulse2.client.launcher.ui.product.LauncherImageSupplier.getImage(Unknown Source)
at com.genuitec.pulse2.client.installer.ui.dialog.InstallerImageService.getImageFromBranding(Unknown Source)
at com.genuitec.pulse2.client.installer.ui.dialog.InstallerImageService.getDialogIcons(Unknown Source)
at com.genuitec.pulse2.client.installer.ui.dialog.ProgressMonitorDialog.createShell(Unknown Source)
at com.genuitec.pulse2.client.installer.ui.dialog.ProgressMonitorDialog.<init>(Unknown Source)
at com.genuitec.pulse2.client.installer.ui.application.PulseApplicationProvisioner.showDialog(Unknown Source)
at com.genuitec.pulse2.client.installer.ui.application.PulseApplicationProvisioner.showDialog(Unknown Source)
at com.genuitec.pulse2.client.launcher.ui.product.LauncherApplication.start(Unknown Source)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)

 

 

So, does anyone meet the same problem before?

Hi,

 

I want to do some research about the apex runtime, I found some info about it on website, but I can't find any info from Salesforce.com.

 

So does anyone know where have an introduction about the apex runtime and usage?

 

Thank you!

Hi,

I have a custom visualforce page. And I have a pageBlockSection with two contents. One is a <apex:tabPanel>, another one is <apex:inputField>.
In tabPanel, I have four <apex:tab> to display a multi picklist. But the contents in each tab, I use the HTML element not the apex tag.

Then I met the following problem,
We know we can collapse the Salesforce sidebar mannually. If I use the apex tag on VF page, when I collapse or open sidebar, the apex tag can adapt the page size automatically. But if I have HTML elements, they can't do this.

Have a look with screenshot:
The "Internal Requirements" is apex tag. The contents in tab are HTML elements.

When collapse sidebar:
User-added image

When expand sidebar:
User-added image

So does anyone know how to resolve this problem?


Hi All,
I am net to Map and need ur help here.

Can anyone help me how to fill value in Map in below example. Can you please help me with the Code?

Map<id,List<Contacts>> CustMap = new Map<Id,List<Contacts>>;

for(Account ac:[SELECT id,name,(SELECT id FROM Contacts) FROM Account])
{
How to fill Map here where Id would be Account Id and Values would be list of Contacts.?
}

Regards,
Varun
 

-----Rollup Summary of Lookup Relationship-------------------------

Hi All,

I want to create a Rollup field in Account Object with Custom Object called 'Contact Partner'.

'Contact Partner' Object is maintaining a lookup relationship with Account Object. 

I want to fill the Rollup field with name 'Total Revenue' in Account object, which should tell the total amount of Revenue generated by each Contact Partner.

Each 'Contact Partner' would be maintaining the field called 'Revenue Generated'.

For Ex

Account A has three Contact Partner(CP) and each CP is generating revenue of 10$,20$ & 30$. Hence the field 'Total Revenue' in Account object should automatically fill  with '60$'

 

Can anyone help me on this along with the Code?, Actually I'm new on the trigger.

Hello,
I am currently using SFDC's Developer Console (because it's on the cloud) but would like to know the opinion of Developers who have worked with (or may have tried) other IDEs for Force.com.
I have come across various alternative IDEs such as:
  1. MavensMate which is not supported any more (Dec-2017) and the owner suggest to look at "Visual Studio Code Extension";
  2. Visual Studio Code Extension;
  3. Welkin Suite (It looks like a paid option but cannot see the price on their website);
  4. Illuminated Cloud (hosted within JetBrains Intellij IDEA); price seem to be 65 USD for 1 or few licenses (and we never know if the vendor will charge new versions)
  5. The traditional Force.com IDE Eclips based (Free but a real pain to install in a Mac);
  6. Any other IDE?
Could you possible let us know your opinion and if you would advise using one or the other? Maybe you could comment on Pros/Cons for each IDE you know?

Thank you very much.
public class Task08 {
     public string keyword{get;set;}
     Set<Account> sette=new Set<Account>(); 
      public Task08(){
      
      sette=[SELECT Name FROM Account ];
      }
     public pagereference Search(){
    
        //sette=[SELECT Name, id,Course_Name__c FROM Group__c ];
         return null;
     }
}
HI Experts 

This is my reuirement.

i have Follow button. for ex: i want count  avalue only one time but here same user clicked multipulle times on button that time i don't want increment count value. please help me how to i will write a logic in method.

 
<apex:commandButton id="CommandButton1" value="Follow" action="{!followOwner}"/>



public Integer followingCount{get;set;}

//Constructor
public userData (ApexPages.StandardController stdController) {
    UserId = UserInfo.getUserId();
    GetCount();
}

 //Method
 public void GetCount() {

 List<User> following = [SELECT Id, Name,title, SmallPhotoUrl FROM User WHERE Id =:parentsetid AND Id !=:u.id order by name]; 
    followingCount = following.size();
 }


Thanks in Advance,
Chanti
 
<apex:page standardController="Case" showHeader="false" >
    <apex:form >
        <apex:pageBlock title="Case Status">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Case.Status}"/>
                <apex:inputField value="{!Case.Reason}"/>
                <apex:inputField value="{!Case.Priority}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="save"/> 
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

when giving reason and status for the case object and saving it. this saved record should be displayed in another new VF page
Please find my trigger and test class in code sample and suggest me how to improve code coverage for helper class.
@isTest(seeAllData=true)
private class Test_OpportunityLineItemCheck 
{
  static testMethod void Checkduplicate() 
  {
        Test.startTest();
		
        User currentUser = [Select Id, UserCountry__c from User where Id = :UserInfo.getUserId() limit 1];
        
        Account accP = new Account(Name = 'Partner1', Account_Type__c = 'VAR - MANAGED', RecordTypeId='01280000000Ln6i', Business_Unit__c = 'CBU', BillingCountry = country);

        insert acc;

        PricebookEntry[] pbes = [Select Id, UnitPrice, CurrencyIsoCode, Pricebook2Id from PricebookEntry where IsActive = true];
            
        Opportunity opp4 = new Opportunity(Name= 'Opp31',Pricebook2Id = pbes[0].Pricebook2Id,RecordTypeId = '01280000000Lnks');
             
        Opportunity[] opplist=new Opportunity[]{opp4};
        insert opplist;
                        
        OpportunityLineItem oli4 = new OpportunityLineItem(OpportunityId = opp4.Id, PricebookEntryId = pbes.get(0).Id);
        
        OpportunityLineItem[] olilist=new OpportunityLineItem[]{oli4};
		
        insert olilist;

        Test.stopTest();  
  }
}


Helper class :
public class OpportunityLineItemCheckOperations {

    public static void checkOnOpportunityLineItems(List<OpportunityLineItem> opportunityProductList){
        
        List<OppWrapper> lstOpps = new List<OppWrapper>();
        Set<String> oppIds = new Set<String>();
        Set<String> productcodeids = new Set<String>();
        
        for (OpportunityLineItem oppline : opportunityProductList){
             productcodeids.add(oppline.productcode);
             oppIds.add(oppline.OpportunityId);
        }
        
        List<Opportunity> lstOppos = [SELECT Id, (SELECT Id, opportunityid, productcode , Product2Id FROM OpportunityLineItems WHERE productcode in :productcodeids)
                                            FROM Opportunity WHERE Id in :oppIds ];
        
        
        for (Opportunity oppor : lstOppos){
        
            for (OpportunityLineItem oppline : oppor.OpportunityLineItems){
                OppWrapper oppo = new OppWrapper();         
                oppo.OppID = oppor.Id;
                oppo.productcode = oppline.productcode;
                //oppo.ProductID = oppline.Product2Id;
                lstOpps.add(oppo);
            }
        }
        
        lstOpps.sort();
        
        for (OpportunityLineItem oppline: opportunityProductList){
            
            for(OppWrapper oppwrap :lstOpps){
                if (oppline.OpportunityId == oppwrap.OppID && oppline.productcode == oppwrap.productcode)
                    oppline.addError('This product is already added to this opportunity.You cannot add the same product again.');
            }
            
        }
        
        
    }
    
    public class OppWrapper implements Comparable{
        String OppID;
        String ProductID;
        String productcode;
        
        public Integer compareTo(Object compareTo){
            OppWrapper compareToCopy = (OppWrapper) compareTo;
            
            Integer returnValue = 0;
            
            if (this.OppID > compareToCopy.OppID)
                returnValue = 1;
                
            else if (this.OppID < compareToCopy.OppID)
                returnValue = -1;
                
            else if (this.OppID == compareToCopy.OppID){
                if (this.ProductID > compareToCopy.ProductID)
                    returnValue = 1;
                    
                else if (this.ProductID < compareToCopy.ProductID)
                    returnValue = -1;
            }
            
            return returnValue;     
        
        }
    
    }

}

 
Hello All,
      I am new to salesforce, I am stuck with outputPanel. I look out visualforce developer guide but still i m confused about it. can anyone exaplain me, why and when to use outputPanel with better example. 
Hi friends,

​I have designed a custom button for sending email. I have a custom table where I'm displaying data. Whenever I'll select any record using checkbox and click that button then that particular record should go as email with that VF template which I'm using. I've designed a Visualforce email template using HTML which is coppy of the main table. I've also written a seperate controller for template but unable to map data. I'm able to send email with that template but records are not coming. I think their is some problem with data mapping with that template. I'm displaying recods in table from 3 different custom objects with Account and contact standard object. Any idea or suggestion or sample code for this requirement?
Thanks in advance.
Rajan
  • November 16, 2017
  • Like
  • 0
I need to create vf page contact 4 checkbox as
Create new account
Create new contact
Create new oppournity
Create new case 
and  next button. If i select any one button need to open create a new acccount/contact/oppournity/case along with search functionality induvidaly ?

How can i acheive it . Bit Urgent Plz




 
Hi, 

I am just wanting to be able to pass the current pages Name to my visualforce page, My visualforce page has a customer controller and is displaying a datatable, I can post both if there are any amendments to the code which might be needed. 

My end goal is to have a button on an account which someone can click and download any (Custom Object) Service Bookings meeting a critea matching the Account ID so that I can create a Proforma Invoice as a PDF. 

Thanks in advance. 
Hi Guys,
  1. Until the Spring 15 release, Maps and Sets are Unordered Collections. So the returned order will be random.
  2. But beginning from Summer 15 release onwards, Maps and Set order is predictable. The order will be same that what you put from the beginning to end.
Example:
Map<String, String> orderedMap = new Map<String, String>();
orderedMap.put('Good', 'This is so good');
orderedMap.put('Bad', 'This is so bad');
System.debug(orderedMap);

If you run the above code snippet in Developer console you will get the returned order as below,

Until Spring 15 Release:

{Bad=This is so bad, Good=This is so good}

From Summer 15 Release:

{Good=This is so good, Bad=This is so bad}

This changes is not the API level, this is Schema level change. If anyone relying on the Map or Set order in your codes, change it as soon. 

Thanks.

Hi,

 

I want to get the "Salesforce.com Certified Administrator"(201) certificate. I have passed DEV 401 before. I want to know whether there have a document for this 201 exam.

 

 

I download the "SGCertifiedAdministrator.pdf" but this is only a simply introduction pdf file. Does salesforce have a detailed ducoment to help us pass the ADM 201 exam?

 

 

Thank you!

Hi, 

 

I use <apex:repeat> in my visualforce email template. And the value for this tag is a list. But actually, I just only want to get one record from this list, maybe first one or last one.

 

So, does anyone know how to achieve this?

 

Thank you!

Hi,

 

I need a custom button display on my standard page layout. When I click this button can send mail to some users.

So I create a custom button, and in the "Behavior" field, I choose "Execute JavaScript". Then I try to invoke my remote action to send maill.

 

if(confirm('Is your Distribution list updated ?')){
    alert('send');
    AuditController.saveAudit(auditData , SaveCallBack, {escape:true});
}
else{
    alert('just save');
}

function SaveCallBack(result, event){
    alert(1);
}

 

But it fail. When code go to the ture condition. There is a error tell me AuditController is not defined.

 

So does anyony know how to send mail by a custom button on the standard pagelayout?

 

Thank you!

Hi,

 

I have a custom object as "A__c". And I create a trigger when I update this object record. This trigger will send mail to some users.

 

Then I create an email visualforce template. And let my trigger invoke this template when I send mail.

But I met a problem about the template.

 

I set the recipientType as "User", and relatedToType as my custom object "A__c"

 

<messaging:emailTemplate subject="Assign Audit" recipientType="User" relatedToType="A__c">
<messaging:plainTextEmailBody >
Hello {!recipient.name}

This is {!relatedTo.Name}

</messaging:plainTextEmailBody>
</messaging:emailTemplate>

When I use "Send Test and Verify Merge Fileds",assign an user and an "A" record, I can see the corresponding value display on this mail body.

 

But if I update a record then the trigger run and invoke this template, the {!recipient.name} can get value and display, but {!relatedTo.Name} can't get any value.

 

 

So does anyone meet this problem before? Or whether I have some wrong code at this template.

 

Thank you!

Hi,

 

I have a problem about visual force table tag.

I use <apex:datatable> in my visualforce page, and I set a dynamic data set for this table. But now I want to set a fixed value at the first row in this table ,then display other dynamic data.

 

Does anyone know how to achieve this?

 

Thank you!

Hi,

 

I want to use jquery to invoke the Apex class. These jquery are written in a HTML page not visualforce page.

 

I have written some JavaScript codes to get the access_token base on OAuth2.0, so when user allow my application access their data, I want to invoke my Apex class in Force.com.

 

The following is my apex class which used the REST architecture.

 

@RestResource(urlMapping='/myservice/*')
global with sharing class MyRestResource{
 
    @HttpGet
    global static list<sObject> getRecord(RestRequest req, RestResponse res)
    {
        String objectType = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        String queryString = 'select name, id from ' + objectType;
        
        List<sObject> objects = Database.query(queryString);
        return objects;
    }
}

 

It will listen the request url which contain /myservice/*

 

Then I use cUrl tools to test this class. By the following command the apex can intercept my request url and return the right result.

 

curl -X GET https: //ap1.salesforce.com/services/apexrest/myservice/Account/ -H "Authorization: OAuth access_token" -H "X-PrettyPrint:1"


So I think I can use this url (https://ap1.salesforce.com/services/apexrest) and packaged the other parts in a jquery.ajax url to achieve the same thing.

But when I did it in a jquery.ajax method I found the ajax can't sent the request by this url pattern.

Code section:

 

$.ajax({
    type:"GET",
    url:"https://ap1.salesforce.com/services/apexrest/myservice/Account",   
    error: function(){alert("error");},
    success: function(){
            alert("Hello");
    },
    beforeSend: function(jqXHR) {
          jqXHR.setRequestHeader("Authorization", "OAuth " + oauthResponse.access_token);
    }
});

But this request can't sent successful by ajax method.

So I think the request url which sent by curl maybe analysis to another pattern in Force.com.

  

Does anyone have experiences in this field which use jquery invoke apex in a HTML page?

 

Thanks!