• Nitish Agrawal
  • NEWBIE
  • 10 Points
  • Member since 2017

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

I am trying to invoke Apex code from custom button on a custom object (Trainee__c) page layout. I am getting error : Unexpected Identifier when I am passing the name field of the custom object in he parameter to Apex method. Following is the code:
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

sforce.apex.execute("PopulateTraineeModule","PopulateTraineeModuleData",
{TraineeName:{!Trainee__c.Name});

alert('Module Data for {!Trainee__c.Name} refreshed');
If I replace  {!Trainee__c.Name} with a hard coded value.. Say 'Atticus Finch' the logic is working fine.
I am also able to see the correct alert message with {!Trainee__c.Name}

Not sure where the problem is.
Following is my Apex Class and method
global class PopulateTraineeModule {

    
    webservice static void PopulateTraineeModuleData (String TraineeName )
    {
...
     }
}




alert('Module Data for {!Trainee__c.Name} refreshed');


 
Hi All,

I am trying to invoke Apex code from custom button on a custom object (Trainee__c) page layout. I am getting error : Unexpected Identifier when I am passing the name field of the custom object in he parameter to Apex method. Following is the code:
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

sforce.apex.execute("PopulateTraineeModule","PopulateTraineeModuleData",
{TraineeName:{!Trainee__c.Name});

alert('Module Data for {!Trainee__c.Name} refreshed');
If I replace  {!Trainee__c.Name} with a hard coded value.. Say 'Atticus Finch' the logic is working fine.
I am also able to see the correct alert message with {!Trainee__c.Name}

Not sure where the problem is.
Following is my Apex Class and method
global class PopulateTraineeModule {

    
    webservice static void PopulateTraineeModuleData (String TraineeName )
    {
...
     }
}




alert('Module Data for {!Trainee__c.Name} refreshed');


 
On my Opportunity object: I have created six custom fields
AVSFQB__Generate_Object__c  (picklist)
AVSFQB__Quickbooks_Id__c  (text 50 - External ID)
AVSFQB__QuickBooks_ItemType__c   (picklist)
Sample_Generate__c  (text 100)
Sample_Quickbooks_ID__c   (text 50)
Sample_QuickBooks_ItemType__c   (text 100)
I have also created a custom button Process_Sample_Sent

I would like to click the button and move the field contents:
AVSFQB__Generate_Object__c to Sample_Generate__c
AVSFQB__Quickbooks_Id__c to Sample_Quickbooks_ID__c
AVSFQB__QuickBooks_ItemType__c to Sample_QuickBooks_ItemType__c

On the custom button, I have selected:
Display type - Detail Page Button
Behavior - Execute JavaScript
Content Source - OnClick JavaScript

I am trying to get this code to work with one set of fields before I add the others

This code produces an "Unexpected identifier error"
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var record = new sforce.SObject("Opportunity__c"); 
record.Id = ("Opportunity__c.Id"); 
record.Sample_Generate__c = {!Opportunity.AVSFQB__Generate_Object__c};
var result = sforce.connection.update([record]); 
// check the result here 
window.location.reload();