3

I am trying to pass a Case SObject to apex class as parameter, but is not working. I did not see the System.debug on the console. Why?

//wire the record
  @wire(getRecord, { recordId: '$recordId', fields })
  case;

  setCaseStatus({
        objCase: this.case // also tried this.case.data
    })
    .then(() => {
        console.log('sucess! ');
    })
    .catch((error) => {
        console.log('Error received: code' + error.errorCode + ', ' +
        'message ' + error.body.message);

    });

//Apex class method
 @AuraEnabled(cacheable=true)
    public static void setCaseStatus(Case objCase){
       System.debug('CaseService.setCaseStatus.case: ' + objCase);

       objCase.status = 'Working';
       update objCase;
    }

Another question: Is it possible apex void method in lwc?

12
  • 3
    Have you reviewed some of the wire recipes in the official repo? There are some examples for what you're trying to do. Also, double check the trailheads on what wire is for, what imperative apex is for, and also check out the lightning data service ui*API adapters for an apex-less way to update your case.
    – tsalb
    Commented Apr 6, 2019 at 21:33
  • Thanks for the answer there is no recipe example send a standard sObject, there is a example with a wrap class is a different case Commented Apr 8, 2019 at 11:48
  • It may have been in another trailhead repo, but you're looking for uiRecordApi and recordUpdate.
    – tsalb
    Commented Apr 8, 2019 at 14:19
  • I am voting to reopen this question as this addresses a problem which is not documented or available in lwc-recipes. I do have an approach here which I would like to add as an answer but cannot add as it's already closed.
    – Jayant Das
    Commented Apr 8, 2019 at 19:00
  • I am voting to leave closed right now for two reasons which are easily fixable. First, "is not working" needs to be more specific. What actual behavior is observed? Is the lack of debug log the only problem? My second issue is the one true question in here doesn't make sense to me. What are you trying to ask by "is it possible apex void method in lwc?"?
    – Adrian Larson
    Commented Apr 8, 2019 at 19:45

1 Answer 1

0

Try with the code below. I'm also a newbie to lwc and there might be a better way to do than this, but this has worked for me.

    import { LightningElement,api,track,wire } from 'lwc';
    import setCaseStatus from '@salesforce/apex/CaseController.setCaseStatus';

    export default class StackExSetCase extends LightningElement {
        @api recordId;
        @api objectApiName;
        @track propselectedStatus = '';
        @wire(setCaseStatus, { propselectedStatus: '$selectedStatus' }) cases;
        handleSave(event) {
            const propselectedStatus = event.target.value;
        }
    }

    <template>
        <lightning-card title="Set Case Status" icon-name="standard:case">
            <div class="slds-m-around_medium">
                <lightning-record-edit-form object-api-name={objectApiName} record-id={recordId}>
                        <lightning-messages></lightning-messages>
                        <lightning-input-field  value={selectedStatus}
                        field-name="Status"
                    ></lightning-input-field>
                    <div class="slds-m-top_medium">
                        <lightning-button variant="brand" type="submit" name="save" label="Save" onclick={handleSave}></lightning-button>
                    </div>
                </lightning-record-edit-form>
            </div>
        </lightning-card>
    </template>

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="stackExSetCase">
    <apiVersion>45.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <objects>
                <object>Case</object>
            </objects>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>
1
  • You have passed the status as parameter I need the Standard sObject case, it is just a studying case not a real business problem Commented Apr 8, 2019 at 11:52

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