1

I have been googling this for a sustained period of time and all the suggestions and solutions I have encountered are still not working.

Ultimate goal: a User clicking a button will write an incremented number value to an existing custom field on the same object and then update that sobject record.

Goal for now: just getting an existing field value to be read by the stupid alert.

Dialog error box:

An Error has Occurred. Error: sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

Code:

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

    var mpArray = [];

try{

    var updateMP = new sforce.SObject("Media_Placement__c");

    updateMP.id = "{!Media_Placement__c.Id}";

    var newNumber = Number(0);

    alert(updateMP.Advertiser__c);

    alert(newNumber);

    mpArray.push(updateMP)
    //alert(updateMediaPlacement.Media_Placement__c.Incorrect_Name_Count__c)

        result = sforce.connection.update([mpArray]);

    if(result[0].success == "true"){
        location.reload();
    }
    else{
        alert(
            "An Error has Occurred. Error: \r\n" +
            result[0].errors.message
        );
    }
}
catch(e){
    alert(
        "An Un-expected Error has Occurred. Error: \r\n" +
        e
    );
} 

1 Answer 1

1

Change

result = sforce.connection.update([mpArray]);

to

result = sforce.connection.update(mpArray);

mpArray is already an array of Sobject

I can confirm that the following works just fine:

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

    var mpArray = [];
    var updateMP = new sforce.SObject("Account");
    updateMP.id = '{!Account.Id}';
    mpArray.push(updateMP);
    result = sforce.connection.update(mpArray);
alert(result);
location.reload();
2
  • Thanks for catching that Eric, great eye! However, I am still getting 'undefined' errors when trying to read from custom fields on the object. However, this: alert(updateMP.Id); statement will display the Id just fine....I'm guessing I need to "query" the fields I want to manipulate using a retrieve function. Strange that I would have to do that on a Detail Page button
    – GPP
    Mar 5, 2017 at 4:35
  • 1
    @GPP - No idea as I do not know what code you are speaking of that is giving you the error. Feel free to accept this as solving the issue and posting a new question about those errors. Please do not modify the question to ask new one. If the code causing the issue is in the code you posted add a comment to let me know which line it is. If you are talking about updateMP.Advertiser__c then yes, you have to use merge syntax '{!Media_Placement__c.Advertiser__c}' dropping the updateMP part to get the value of the current record or query for it
    – Eric
    Mar 5, 2017 at 4:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .