• Saurav Roy 15
  • NEWBIE
  • 45 Points
  • Member since 2018

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

Could you please look into the code and let me know where i am wrong.
I am trying the retrieve the list of accounts using imperative method. The data is not retrieving and it the going to the catch error block.
 
Apex Class
public with sharing class ContactListService {
@AuraEnabled
    public static List<Object> getAcountList(String name){
        String key = '%'+name+'%';
        String accQuery = 'select id, name, email, phone from Account where name like : key';
        System.debug('Query --- '+Database.query(accQuery));
        return Database.query(accQuery);
        
    }
}

JS File:
import { LightningElement, track } from 'lwc';
import getAcountList from '@salesforce/apex/ContactListService.getAcountList';
export default class ContactList extends LightningElement {
    
    @track accounts;
    @track errorAccount;
    @track searchAccount;

    handleChangeAccount(event){
        //event.preventDefault();
        console.log('Value '+event.target.value);
        this.searchAccount = event.target.value;
    }
    
    //Imperative method
    findaccounts(){
        getAcountList({
		name : this.searchAccount
	})
        .then(result =>{
            console.log('Result----'+result);
                this.accounts = result;
        })
        .catch(error=>{
                this.errorAccount = error;
                console.log('Error ----'+error);
        });
    }
}


HTML:
<template>
	<lightning-card>
	    <lightning-layout vertical-align="center">
                  <lightning-layout-item padding="around-small">
                      <lightning-input label="Find Account" value={searchAccount} onchange={handleChangeAccount}></lightning-input>
            	</lightning-layout-item>
            
		<lightning-layout-item padding="around-small">
                	<lightning-button label="Find Accounts" varient="brand" onclick={findaccounts}></lightning-button>
           	</lightning-layout-item>
    
            	<lightning-layout-item padding="around-small">
                	<template for:each={accounts} for:item="acc">
                    		<p key={acc.id}>{acc.Name}</p>
        		</template>
            	</lightning-layout-item>
            </lightning-layout>
	</lightning-card>
</template>

User-added image

Thanks
Saurav
 
Hi Everyone,
Can you please help me out, I am new to Integration. Trying to create a record from one Salesforce Org to another Org (SOAP).
The WSDL file that I have generated for the apex class is more than 1MB. So I have removed some of the code from WSDL file to be able to generate wsdl2apex.
Error: System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element Id

Apex Class in Org1:
global class BookPlanner { 
    global class BookPlan{
        webservice String bookName;
        webservice Decimal price;
        webservice String bookId;
    }
    webservice static Book__c createBook(BookPlan Bk){
        Book__c book = new Book__c();
        book.Name = Bk.bookName;
        book.Price__c = Bk.price;
        insert Book;
        //Bk.bookId = book.Id;
        return Book;
    }
}
Call out Class of Org2:
public class Org2Integration {
    
    String Username = '*************************';
    String Password = '**************************';
	partnerSoapSforceCom_IntegratedOrg.Soap Obj = new partnerSoapSforceCom_IntegratedOrg.Soap();
    partnerSoapSforceCom_IntegratedOrg.LoginResult loginResult =  Obj.Login(Username,Password);
    System.debug('Successfull Login ------------------------------- '+loginResult);
    String Org2SessionId = loginResult.sessionId;
    System.debug('Session ID Org2 '+ Org2SessionId);
    
    // Get the sessionId from loginResult and use it into the sessionHeader_element
    BookPlannerSfdcIntegration.BookPlanner Org2CreateBook = new BookPlannerSfdcIntegration.BookPlanner();
    BookPlannerSfdcIntegration.SessionHeader_element sessionHeader = new BookPlannerSfdcIntegration.SessionHeader_element();
    sessionHeader.sessionId = Org2SessionId;
    System.debug('sessionHeader: '+ sessionHeader.sessionId);
    
    Org2CreateBook.SessionHeader = sessionHeader;
    //Org2CreateBook.URL = loginResult.serverURL;
    
    //Creating Book Record
    BookPlannerSfdcIntegration.BookPlan Book = new BookPlannerSfdcIntegration.BookPlan();
    Book.bookName = 'Integration Book Version 1';
    Book.price = 3000.00;
    
    //XML Headers
    Map<String,String> inputHeaderMap = new Map<String,String>();
    inputHeaderMap.put('Content-Type', 'text/xml');
    inputHeaderMap.put('Accept', 'text/xml');
    inputHeaderMap.put('SoapAction','');
    Org2CreateBook.inputHttpHeaders_x = inputHeaderMap;
    
    BookPlannerSfdcIntegration.Book_xc result = Org2CreateBook.createBook(Book);  
    
}


 
Hi All,

Apart from visual force pages, what can be edited directly in production?
Hello Everyone,
Can anyone please explain the significance of the Test.startTest() and Test.stopTest() in terms of asynchronous calls/apex ? I am aware of the governer limits being reset. 
Hi All,

Can anyone please help me. I am new to Salesforce.
I am getting Record read-only error while trying to update a field in Account object in a before trigger. 
Created a new field as Previous_Type__c which will store the Previous value of Account Type.
Trigger: 
trigger AccountTypeUpdate on Account (before update) {
    
    if(Trigger.isBefore && Trigger.isUpdate){
        if(AccountTypeUpdateClass.isTriggerExecuted){
                   AccountTypeUpdateClass.isTriggerExecuted = false;
        
                for(Account Acc: Trigger.old){
                    AccountTypeUpdateClass.ChangeType(Acc);   
                }  
        }
    }
}
Apex Class:
public class AccountTypeUpdateClass {
    public static boolean isTriggerExecuted = True;  
        public static void ChangeType(Account obj)
        {
                obj.Previous_Type__c = obj.Type;
        } 
}

Error Message:
AccountTypeUpdate: execution of BeforeUpdate caused by: System.FinalException: Record is read-only Class.AccountTypeUpdateClass.ChangeType: line 5, column 1 Trigger.AccountTypeUpdate: line 8, column 1
Hello Everyone,
Can anyone please explain the significance of the Test.startTest() and Test.stopTest() in terms of asynchronous calls/apex ? I am aware of the governer limits being reset. 
Hi All,

Could you please look into the code and let me know where i am wrong.
I am trying the retrieve the list of accounts using imperative method. The data is not retrieving and it the going to the catch error block.
 
Apex Class
public with sharing class ContactListService {
@AuraEnabled
    public static List<Object> getAcountList(String name){
        String key = '%'+name+'%';
        String accQuery = 'select id, name, email, phone from Account where name like : key';
        System.debug('Query --- '+Database.query(accQuery));
        return Database.query(accQuery);
        
    }
}

JS File:
import { LightningElement, track } from 'lwc';
import getAcountList from '@salesforce/apex/ContactListService.getAcountList';
export default class ContactList extends LightningElement {
    
    @track accounts;
    @track errorAccount;
    @track searchAccount;

    handleChangeAccount(event){
        //event.preventDefault();
        console.log('Value '+event.target.value);
        this.searchAccount = event.target.value;
    }
    
    //Imperative method
    findaccounts(){
        getAcountList({
		name : this.searchAccount
	})
        .then(result =>{
            console.log('Result----'+result);
                this.accounts = result;
        })
        .catch(error=>{
                this.errorAccount = error;
                console.log('Error ----'+error);
        });
    }
}


HTML:
<template>
	<lightning-card>
	    <lightning-layout vertical-align="center">
                  <lightning-layout-item padding="around-small">
                      <lightning-input label="Find Account" value={searchAccount} onchange={handleChangeAccount}></lightning-input>
            	</lightning-layout-item>
            
		<lightning-layout-item padding="around-small">
                	<lightning-button label="Find Accounts" varient="brand" onclick={findaccounts}></lightning-button>
           	</lightning-layout-item>
    
            	<lightning-layout-item padding="around-small">
                	<template for:each={accounts} for:item="acc">
                    		<p key={acc.id}>{acc.Name}</p>
        		</template>
            	</lightning-layout-item>
            </lightning-layout>
	</lightning-card>
</template>

User-added image

Thanks
Saurav
 
Hello Everyone,
Can anyone please explain the significance of the Test.startTest() and Test.stopTest() in terms of asynchronous calls/apex ? I am aware of the governer limits being reset. 
Hi All,

Can anyone please help me. I am new to Salesforce.
I am getting Record read-only error while trying to update a field in Account object in a before trigger. 
Created a new field as Previous_Type__c which will store the Previous value of Account Type.
Trigger: 
trigger AccountTypeUpdate on Account (before update) {
    
    if(Trigger.isBefore && Trigger.isUpdate){
        if(AccountTypeUpdateClass.isTriggerExecuted){
                   AccountTypeUpdateClass.isTriggerExecuted = false;
        
                for(Account Acc: Trigger.old){
                    AccountTypeUpdateClass.ChangeType(Acc);   
                }  
        }
    }
}
Apex Class:
public class AccountTypeUpdateClass {
    public static boolean isTriggerExecuted = True;  
        public static void ChangeType(Account obj)
        {
                obj.Previous_Type__c = obj.Type;
        } 
}

Error Message:
AccountTypeUpdate: execution of BeforeUpdate caused by: System.FinalException: Record is read-only Class.AccountTypeUpdateClass.ChangeType: line 5, column 1 Trigger.AccountTypeUpdate: line 8, column 1