• yogeshRao
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
Basically i have the following loop and when i run it through process builder i get the bottom error:

The code is below
 
public with sharing class TrelloInvocable {
    /**
     * @description     Create a list and runs that through the Trello API Callout Class
     * @param           ticketIds is the list that is presented to the method
    */
    @InvocableMethod(label='Create trello cards' description='Will attempt to Create a new trello card for each id')
	public static void TrelloInvocableMethod (List<Id> ids){
        for (Id id : ids){
            System.debug(id);
            TrelloAPICalloutClass.trellocreatenew(id);
        }
  }
}

It fires this code:
 
public static void trellocreatenew(string ID){
        
        	// Get the ticket details
        	Ticketing__C ticket = [SELECT id,name,Trello_Card_Title__c,Trello_Card_Description__c,trello_card_URL__C,Trello_Card_Raised__C 
                                   FROM ticketing__C 
                                   Where ID = :ID];
        	system.debug('The ticket id = '+ticket.id 
                         +'\n The Ticket number is'+ ticket.Name 
                         + '\n The Trello card title is '+ ticket.trello_card_title__C
                         + '\n The trello card description is ' + ticket.Trello_Card_Description__c);
        
        
        	// get connection details from custom settings
        	TrelloConnectionDetails__c connection = TrelloConnectionDetails__c.getOrgDefaults();
        	string key = connection.Key__c;
        	string token = connection.Token__c;
        	string idlist = connection.Id_List__c;
        	string name = encodingUtil.urlEncode(ticket.Trello_Card_Title__c, 'UTF-8');
        	string postcardurl = connection.PostCard__c;
        	string endpointurl = postcardurl.replace('{key}', key)
                							.replace('{token}', token)
                							.replace('{name}',name)
                							.replace('{idlist}', idlist);
            string body = '{"desc":'
                			+ Json.serialize(ticket.Trello_Card_Description__c)
                			+'}';
    		system.debug(body);
        	system.debug(endpointurl);
        
 
        	//submit the http request to trello
            HttpRequest request = new HttpRequest();
            http http = new Http();
            request.setEndpoint(endpointurl);
            request.setMethod('POST');
            request.setHeader('Content-Type', 'application/json;charset=UTF-8');
            request.setBody(+body);
            HttpResponse response = http.send(request);
        
            //check if we get a good response from trello
            if (response.getstatuscode() == 200){
                //Deserializes the JSON string into collections of primitive data types
                Map <string, Object> results = (map<string, object>) json.deserializeUntyped(response.getBody());
                system.debug(results);
                    if(results.containsKey('shortUrl')){
                    string returnedURL = String.valueOf(results.get('shortUrl'));
                    ticket.Trello_Card_URL__c = returnedURL;
                    system.debug(returnedURL);
                    //Update ticket;
                    }
             } Else {
                  System.debug('The status code returned was not expected: ' +
                    response.getStatusCode() + ' ' + response.getStatus());
                 }
            
            
              
        }
            
    }

However it gives this error:

We can't save this record because the “Assign new ticket to a Inbound Ticket Queue” process failed. Give your Salesforce admin these details. An Apex error occurred: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Error ID: 1425857253-83851 (194658065)

Any help would be fab as i do not understand the issue.

This is my first shot at apex so if it simple i do appologise.
Basically i have the following loop and when i run it through process builder i get the bottom error:

The code is below
 
public with sharing class TrelloInvocable {
    /**
     * @description     Create a list and runs that through the Trello API Callout Class
     * @param           ticketIds is the list that is presented to the method
    */
    @InvocableMethod(label='Create trello cards' description='Will attempt to Create a new trello card for each id')
	public static void TrelloInvocableMethod (List<Id> ids){
        for (Id id : ids){
            System.debug(id);
            TrelloAPICalloutClass.trellocreatenew(id);
        }
  }
}

It fires this code:
 
public static void trellocreatenew(string ID){
        
        	// Get the ticket details
        	Ticketing__C ticket = [SELECT id,name,Trello_Card_Title__c,Trello_Card_Description__c,trello_card_URL__C,Trello_Card_Raised__C 
                                   FROM ticketing__C 
                                   Where ID = :ID];
        	system.debug('The ticket id = '+ticket.id 
                         +'\n The Ticket number is'+ ticket.Name 
                         + '\n The Trello card title is '+ ticket.trello_card_title__C
                         + '\n The trello card description is ' + ticket.Trello_Card_Description__c);
        
        
        	// get connection details from custom settings
        	TrelloConnectionDetails__c connection = TrelloConnectionDetails__c.getOrgDefaults();
        	string key = connection.Key__c;
        	string token = connection.Token__c;
        	string idlist = connection.Id_List__c;
        	string name = encodingUtil.urlEncode(ticket.Trello_Card_Title__c, 'UTF-8');
        	string postcardurl = connection.PostCard__c;
        	string endpointurl = postcardurl.replace('{key}', key)
                							.replace('{token}', token)
                							.replace('{name}',name)
                							.replace('{idlist}', idlist);
            string body = '{"desc":'
                			+ Json.serialize(ticket.Trello_Card_Description__c)
                			+'}';
    		system.debug(body);
        	system.debug(endpointurl);
        
 
        	//submit the http request to trello
            HttpRequest request = new HttpRequest();
            http http = new Http();
            request.setEndpoint(endpointurl);
            request.setMethod('POST');
            request.setHeader('Content-Type', 'application/json;charset=UTF-8');
            request.setBody(+body);
            HttpResponse response = http.send(request);
        
            //check if we get a good response from trello
            if (response.getstatuscode() == 200){
                //Deserializes the JSON string into collections of primitive data types
                Map <string, Object> results = (map<string, object>) json.deserializeUntyped(response.getBody());
                system.debug(results);
                    if(results.containsKey('shortUrl')){
                    string returnedURL = String.valueOf(results.get('shortUrl'));
                    ticket.Trello_Card_URL__c = returnedURL;
                    system.debug(returnedURL);
                    //Update ticket;
                    }
             } Else {
                  System.debug('The status code returned was not expected: ' +
                    response.getStatusCode() + ' ' + response.getStatus());
                 }
            
            
              
        }
            
    }

However it gives this error:

We can't save this record because the “Assign new ticket to a Inbound Ticket Queue” process failed. Give your Salesforce admin these details. An Apex error occurred: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out Error ID: 1425857253-83851 (194658065)

Any help would be fab as i do not understand the issue.

This is my first shot at apex so if it simple i do appologise.
I have a requirement to enable a component based on selection in the page. Below is the screenshot of my page

LookupControllerImageFrom the above image, when a radio button is clicked, below lookup box should be enabled and when these two selections are made, next button should be enabled.

As of now, they are not dependent on any selections.

Below is my LWC code:

LookupController apex class:
public with sharing class LookupController {
    public LookupController() {

    }

    @AuraEnabled(cacheable=true)
    public static List<SObJectResult> getResults(String ObjectName, String fieldName, String value) {
        List<SObJectResult> sObjectResultList = new List<SObJectResult>();
        system.debug(fieldName+'-------------'+ObjectName+'---++----------'+value);
        if(String.isNotEmpty(value))
            for(sObject so : Database.Query('Select '+fieldName+' FROM '+ObjectName+' WHERE '+fieldName+' LIKE \'%' + value + '%\'')) {
                String fieldvalue = (String)so.get(fieldName);
                sObjectResultList.add(new SObjectResult(fieldvalue, so.Id));
            }
        
        return sObjectResultList;
    }
    
    public class SObJectResult {
        @AuraEnabled
        public String recName;
        @AuraEnabled
        public Id recId;
        
        public SObJectResult(String recNameTemp, Id recIdTemp) {
            recName = recNameTemp;
            recId = recIdTemp;
        }
    }
}

LookupController LWC HTML:
<template>
    <br>
    <fieldset class="slds-form-element">
        <legend class="slds-form-element__legend slds-form-element__label">Operation</legend>
        <div class="slds-form-element__control">
    <span class="slds-radio">
      <input type="radio" id="radio-43" value="radio-43" name="default" checked="" />
      <label class="slds-radio__label" for="radio-43">
        <span class="slds-radio_faux"></span>
        <span class="slds-form-element__label">Insert</span>
      </label>
    </span>
            <span class="slds-radio">
      <input type="radio" id="radio-44" value="radio-44" name="default" />
      <label class="slds-radio__label" for="radio-44">
        <span class="slds-radio_faux"></span>
        <span class="slds-form-element__label">Update</span>
      </label>
    </span>
        </div>
    </fieldset>
    <br><br>
    <lightning-card>
        <h3 slot="title">
            <lightning-icon icon-name="utility:search" size="small"></lightning-icon>
            Search Objects below
        </h3>
        <div slot="footer">

        </div>
        <div>

            <div class="slds-form-element">


                <div class="slds-form-element__control">
                    <div class="slds-combobox_container">

                        <div class={txtclassname} data-id="resultBox" aria-expanded="False" aria-haspopup="listbox" role="combobox">
                            <div class="slds-form-element__control slds-input-has-icon slds-input-has-icon slds-input-has-icon_left-right" role="none">

                                <div>
                                    <span class="slds-icon_container slds-icon-utility-search slds-input__icon iconheight">
                                        <lightning-icon class="slds-icon slds-icon slds-icon_small slds-icon-text-default" icon-name={iconName} size="x-small" alternative-text="icon" ></lightning-icon>
                                    </span>
                                </div>
                                <lightning-input required={required} read-only={inputReadOnly} data-id="userinput" label={Label} name="searchText" onchange={searchField} value={selectRecordName} class="leftspace"></lightning-input>

                                <div if:true={iconFlag}>
                                    <span class="slds-icon_container slds-icon-utility-search slds-input__icon slds-input__icon_right iconheight">
                                        <lightning-icon class="slds-icon slds-icon slds-icon_small slds-icon-text-default" icon-name="utility:search" size="x-small" alternative-text="icon" ></lightning-icon>
                                    </span>
                                </div>
                                <div if:true={clearIconFlag}>
                                    <button class="slds-input__icon slds-input__icon_right slds-button slds-button_icon iconheight" onclick={resetData}>
                                        <lightning-icon class="slds-icon slds-icon slds-icon_small slds-icon-text-default" icon-name="utility:clear" size="x-small" alternative-text="icon" ></lightning-icon>
                                        <span class="slds-assistive-text">Clear</span></button>
                                </div>
                            </div>

                            <!-- Second part display result -->
                            <div id="listbox-id-1" class="slds-dropdown slds-dropdown_length-with-icon-7 slds-dropdown_fluid" role="listbox">
                                <ul class="slds-listbox slds-listbox_vertical" role="presentation">
                                    <template for:each={searchRecords} for:item="serecord">
                                        <li role="presentation" class="slds-listbox__item" key={serecord.recId}>

                                            <div data-id={serecord.recId} data-name={serecord.recName} onclick={setSelectedRecord} class="slds-media slds-listbox__option slds-listbox__option_entity slds-listbox__option_has-meta" role="option">
                                                <span class="slds-media__figure">
                                                    <span class="slds-icon_container slds-icon-standard-account">
                                                        <lightning-icon icon-name={iconName} class="slds-icon slds-icon slds-icon_small slds-icon-text-default" size="x-small"></lightning-icon>
                                                    </span>
                                                </span>
                                                <span class="slds-media__body">
                                                    <span class="slds-listbox__option-text slds-listbox__option-text_entity">{serecord.recName}</span>
                                                    <span class="slds-listbox__option-meta slds-listbox__option-meta_entity">{objectName} • {serecord.recName}</span>
                                                </span>
                                            </div>
                                        </li>
                                    </template>
                                </ul>
                            </div>
                            <div if:true={messageFlag}>
                                No result found.
                            </div>
                            <div if:true={LoadingText}>
                                Loading...
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </lightning-card>
    <br> <br>
    <a class="slds-button slds-button_brand" href="javascript:void(0);">Next</a>
</template>

JS Code:
import { LightningElement,wire,api,track } from 'lwc';
import getResults from '@salesforce/apex/LookupController.getResults';


export default class LwcCustomLookup extends LightningElement {
    @api objectName = 'EntityDefinition';
    @api fieldName = 'QualifiedApiName';
    @api selectRecordId = '';
    @api selectRecordName;
    @api Label;
    @api searchRecords = [];
    @api required = false;
   //   @api iconName = 'standard:event'
    @api LoadingText = false;
    @track txtclassname = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click';
    @track messageFlag = false;
    @track iconFlag =  true;
    @track clearIconFlag = false;
    @track inputReadOnly = false;


    searchField(event) {
        var currentText = event.target.value;
        this.LoadingText = true;

        getResults({ ObjectName: this.objectName, fieldName: this.fieldName, value: currentText  })
            .then(result => {
                this.searchRecords= result;
                this.LoadingText = false;

                this.txtclassname =  result.length > 0 ? 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open' : 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click';
                if(currentText.length > 0 && result.length == 0) {
                    this.messageFlag = true;
                }
                else {
                    this.messageFlag = false;
                }

                if(this.selectRecordId != null && this.selectRecordId.length > 0) {
                    this.iconFlag = false;
                    this.clearIconFlag = true;
                }
                else {
                    this.iconFlag = true;
                    this.clearIconFlag = false;
                }
            })
            .catch(error => {
                console.log('-------error-------------'+error);
                console.log(error);
            });

    }

    setSelectedRecord(event) {
        var currentRecId = event.currentTarget.dataset.id;
        var selectName = event.currentTarget.dataset.name;
        this.txtclassname =  'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click';
        this.iconFlag = false;
        this.clearIconFlag = true;
        this.selectRecordName = event.currentTarget.dataset.name;
        this.selectRecordId = currentRecId;
        this.inputReadOnly = true;
        const selectedEvent = new CustomEvent('selected', { detail: {selectName, currentRecId}, });
        // Dispatches the event.
        this.dispatchEvent(selectedEvent);
    }

    resetData(event) {
        this.selectRecordName = "";
        this.selectRecordId = "";
        this.inputReadOnly = false;
        this.iconFlag = true;
        this.clearIconFlag = false;

    }

}

Is there any way I can enable the components based on other component selections. Please suggest
<aura:attirbute name="LeadObj" type="Lead"/>
<lightning:recordEditForm objectApiName="Lead" >
    <lightning:inputField aura:id="accid" fieldName="Account__c" value="{!v.LeadObj.Account__c}" label="Attribute" onchange="{!c.myChangeAcc}"/>
</lightning:recordEditForm>



controller.js

mychangeAcc:function(component,event,helper){
var acc=component.find('accid').get('v.value');
alert(acc);
var action = component.get("c.LeadAccountInfo");

        action.setParams({ldvalue:acc});

}

apex class:

@AuraEnabled
    public static string LeadAccountInfo(Id ldvalue){
Account ac=[select id,Name from Account where Id =:ldvalue limit 1];
        return ac.Name;
}

Hi All ,here in thee above acode it is not passing parameter to apex class. if i test with harcoded id its working 

can anyone help

Thanks,
Billing Badge
Hi,

Is there any way to get Lightning-input-field value inside js controller of Lightning web component?

Thanks
Hi Guys,

When I'm trying to Create a project in the VS Code, I'm not able to create a project as it is running for a very long time.

When I'm trying to look into the Developer:Show Running extensions it is displaying the below error.

PFA, For the same.

User-added imageCan anyone help me out?
 
Newbie question.  I have a simple LWC component where I am using imperative apex to return a List<Custom Apex Class> that is not wired or cacheable.  I want to immediately display this data in the component.

What "hook" should I use to invoke my imperative apex?.  Here is my current code but I have got to believe there is an easier way to display data on the 'open' of a component when you cannot use @wire or the other pre-cooked approaches.

import { LightningElement, api, wire } from 'lwc';
import getStatusList from '@salesforce/apex/BrokerLoadStatus2Controller2.getStatusList';
export default class BrokerLoadStatus extends LightningElement {
    @api recordId;    
    statusList;
    error;
    constructor() {
        super();
        this.firstTime = true;
    }
    renderedCallback() {
        if(this.firstTime) {
            this.getLoadStatus();
            this.firstTime = false;
        }
    }
    getLoadStatus() {        
        getStatusList({loadId: this.recordId})
            .then(result => {
                this.statusList = result;
                this.error = undefined;
            })
            .catch(error => {
                this.statusList = undefined;
                this.error = error;
            });
    }    
}
// EOF