• sudhir kumar kokila
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,
 I am not able to insert records itno custom object. See the below code.
(My Requirement is when i click on custom button need to insert values in another object)

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 

var callout = "" + sforce.apex.execute("MyWebservice","myFunction",
    {param1:"{!Segment__c.Event__c}",param2:"{!Segment__c.Member_Name__c}"}); 


    if (callout == 'OK') { 
    alert("Webservice call was ok."); 
    window.location.reload(); 

else { 
    alert("Webservice call failed!"); 
}


global without sharing class MyWebservice {

    WebService static String myFunction(String param1,string param2) {

        if (String.isNotBlank(param1)) {

            try {
            
          Segment2__c Segment= new Segment2__c();
            Segment.Name='Karthik';
            Segment.Event__c= param1;
            Segment.Member_Name__c= param2;
             insert Segment;        
           
               return 'OK';    
            }
            catch (Exception e) {
                return 'ERROR';
            }
        }
        else {
            return 'ERROR';
        }
    }
}

I am calling myFunction from script I am getting responce OK But record is not inserting in the object.

Any one please respond quickly 

Thanks in advance.