• Ghanesan
  • NEWBIE
  • 50 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 6
    Replies
Hi, 

I am working on opportunity object, i have created the list view button for new opty creation. The requirement is when we choose the business type custom field which is recordtype field, the record should create with that recordtype and its respective fields. the problem in my lwc code is the record get created but its having only the standard fields and respective fields for recordtype is not there in record. below is my code. 


HTML:
<!--
  @description       :
  @author            : ChangeMeIn@UserSettingsUnder.SFDoc
  @group             :
  @last modified on  : 12-03-2022
  @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
-->
<template>
    <template if:true={isOpen}>
      <c-modal onclose={closeHandler}>
            <template if:true={iscreatenewopty}>
            <lightning-record-edit-form object-api-name="Opportunity" onsuccess={handleSuccess} onerror={handleError}>
                    <lightning-card title="New Opportunity ">
                        <lightning-layout>
                            <lightning-layout-item size="6" padding="around-small">
                                <lightning-card title="Create A New Opportunity ">
                                    <lightning-output-field field-name="OwnerId"></lightning-output-field>
                                    <lightning-input-field field-name="Name"></lightning-input-field>
                                    <lightning-input-field field-name="AccountId"></lightning-input-field>
                                    <lightning-input-field field-name="Working_Month__c" required="true"></lightning-input-field>
                                    <lightning-input-field field-name="Total_Contract_Value__c"></lightning-input-field>
                                    <lightning-input-field field-name="Department__c" required="true"></lightning-input-field>
                                    <lightning-input-field field-name="Term__c"></lightning-input-field>
                                 </lightning-card>
                            </lightning-layout-item>
                            <lightning-layout-item size="6" padding="around-small">
                                <lightning-card >
                                    <lightning-input-field field-name="Business_Type__c"></lightning-input-field>
                                    <lightning-input-field field-name="CloseDate"></lightning-input-field>
                                    <lightning-input-field field-name="StageName"></lightning-input-field>
                                    <lightning-input-field field-name="Forecast_Category__c"></lightning-input-field>
                                    <lightning-input-field field-name="Probability"></lightning-input-field>
                                    <lightning-input-field field-name="Amount"></lightning-input-field>
                                    <lightning-input-field field-name="Contract_duration__c"></lightning-input-field>
                                    <lightning-input-field field-name="Forecast_Category__c"></lightning-input-field>
                                </lightning-card>
                            </lightning-layout-item>
                        </lightning-layout>                              
                    </lightning-card>              
            </lightning-record-edit-form>
            <div slot="footer">
                <button class="slds-button slds-button_brand" onclick={handleSubmitButtonClick}>Save and Create Service</button>
             <lightning-button icon-name="utility:delete" class="slds-p-around_large" variant="destructive" padding="around-large" type="submit" label="cancel" onclick={closeHandler}></lightning-button>
            </div>
        </template>
        <template if:false={iscreatenewopty}>
            <c-create-Opty-Service opportunity-id={opportunityId}>
             </c-create-Opty-Service>
          </template>
         </c-modal>
                </template>
            </template>
Js: 

import { LightningElement,track } from 'lwc';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
export default class CreateNewOpty extends LightningElement {
    @track opportunityId = ''
    isOpen = true  
    iscreatenewopty = true
    openHandler(){
        console.log("Clicked!!")
        this.isOpen = true
    }      
    closeHandler(){
        this.isOpen = false
    }  
    handleClose(event){
        this.rating = '0';
        this.cancel = true;
        this.handleSubmit(event);
    }
    handleSubmitButtonClick(event){  
        event.preventDefault();    
      //  console.log("id of created :"+id)
     
      const fields = this.template.querySelector('lightning-record-edit-form').fields;
      console.log('-----------------------');
      console.log(fields);
        var isVal = true;
        this.template.querySelectorAll('lightning-input-field').forEach(element => {
            isVal = isVal && element.reportValidity();
        });
        if (isVal) {                
            this.template.querySelector('lightning-record-edit-form').submit();    
               
     
        } else {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: 'Please enter all the required fields',
                    variant: 'error',
                }),
            );
        }
     }
     handleSuccess(event) {
        this.opportunityId = event.detail.id;
        console.log("id of created :"+this.opportunityId)
        this.iscreatenewopty=false;
        this.showSuccessNotification(this.opportunityId);
    }
    handleError(event) {
        console.log(JSON.stringify(event.detail))
        this.dispatchEvent(
            new ShowToastEvent({
                title: event.detail.output.errors[0].errorCode,
                message: event.detail.detail,
                variant: 'error',
            }),
        );
    }
    showSuccessNotification(opportunityId){            
        const event = new ShowToastEvent({
            title: "Success",
            message: "Opportunity Created Successfully - "+opportunityId,
            variant:"Success"
        });
        this.dispatchEvent(event);
    }
}
Getting this error for the below apex test class: 

Apex Handler: 
public class InsertIncomeRecordHandler {
    public static void insertRecord(List<Salary_Detail__c> salList,Map<id,Salary_Detail__c> oldMap){
        Set<Id> empId = new Set<Id>();
        List<D_Transaction__c> dList = new List<D_Transaction__c>();
        ID income = Schema.SObjectType.D_Transaction__c.getRecordTypeInfosByName().get('Income').getRecordTypeId();
        ID trans = Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('Transaction').getRecordTypeId();
        ID expense = Schema.SObjectType.D_Transaction__c.getRecordTypeInfosByName().get('Expense').getRecordTypeId();
        
        for(Salary_Detail__c sd : salList){
            if(sd.Advance__c != oldMap.get(sd.Id).Advance__c && sd.Isdetected__c !=oldMap.get(sd.Id).Isdetected__c){
            if(sd.Advance__c >0 && sd.RecordTypeId == trans && sd.Organization__c == 'Deshkal'){
                empId.add(sd.Employee_Information__c);
            }
            }
            
            system.debug(' empIdt' + empId);
        }
        
      
        for(Employee_Information__c emp : [select id,Name From Employee_Information__c where id IN :empId]){
        for(D_Transaction__c dt : [SELECT RecordTypeId,D_Amount__c,D_Employee__c,D_Advance_Status__c,D_Advance_Repay__c,D_Name__c FROM D_Transaction__c where D_Employee__c =:emp.Id AND RecordTypeId =:expense AND D_Advance_Status__c = 'Open' ]){
            
                D_Transaction__c d = new D_Transaction__c();
                d.D_Employee__c = emp.Id;
                d.RecordTypeId = income;
                d.D_Transaction__c =dt.Id;
                Integer result = integer.valueOf(dt.D_Amount__c) / integer.valueOf(dt.D_Advance_Repay__c);
                d.D_Amount__c = result;
                system.debug('d.D_Amount__c');
                dList.add(d);
            
        }
        }
        
        if(!dList.isEmpty()){
            insert dList;
        }
    }
}


Test Class:
@isTest
private class InsertIncomeRecordHandlerTest {

    @isTest
    static void testInsertRecord() {
        // Create test data
        Employee_Information__c emp = new Employee_Information__c();
        emp.Salutation__c = 'Mr.';
        emp.Name = 'Test';
        emp.Employee_Last_Name__c = 'HR Admin';
        emp.Date_of_Join__c = system.today();
        emp.Gender__c = 'Male';
        emp.Personal_Email__c = 'abc@gmail.com';
        emp.Marital_Status__c = 'Single';
        emp.Employment_Status__c = 'Active';
        emp.DN_Designation__c='CEO';
        emp.Date_of_Birth__c=Date.newInstance(2000, 12, 9);
        emp.Gender__c='Male';
        emp.Manager_Supervisor__c = 'Deepu H D';
        emp.Work_Location__c = 'NOC';
        emp.Bank_Name__c='HDFC';
        emp.Account_Number__c='12345678901234';
        emp.Mobile_Number__c='9999999999';
        emp.IFSC_CODE__c='HDFC0000003';
        emp.Confirmed_CTC__c=800000;
        emp.Basic_Percentage__c='40';
        emp.Tax_Regime__c='Old Regime';
       emp.PFs__c='Percentage';
        emp.Marital_Status__c='Single';
        emp.Aadhaar_Number__c='265385644663';
        emp.Address__c='Test';
        emp.City__c='Chennai';
       emp.Organization__c='Deshkal';
        emp.Postal_Code__c='600001';
      emp.DN_Leave_Process__c='Yes';
        insert emp;

        Salary_Detail__c salary = new Salary_Detail__c(
            Employee_Information__c = emp.Id,
            RecordTypeId = Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('Transaction').getRecordTypeId(),
            Advance__c = 60,
            Isdetected__c = false,
            Organization__c = 'Deshkal'
        );
        insert salary;

        
      D_Transaction__c dt = new D_Transaction__c ();
             dt.D_Employee__c = emp.Id;
        dt.D_Amount__c = 100;
            dt.D_Advance_Repay__c =' 12';
            dt.RecordTypeId = Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('expense').getRecordTypeId();
        dt.D_Advance_Status__c = 'Open';
                
                               
                     

       
        Test.startTest();
insert dt;
        Test.stopTest();
        
      }
        



}
 
Hi ,
Getting this error "List has no rows for assignment to SObject"
Trying to create button through vf page. When button is clicked, the date field should update. below is my code. 

Controller: 
public class ResignationButtonClass {
    public Employee_Information__c emp;
           public ResignationButtonClass() {
        emp = [SELECT DN_Employee_ID__c FROM Employee_Information__c 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Employee_Information__c getemp() {
        return emp;
    }
                   public PageReference Resign() {
                      pagereference redirect = new PageReference('/apex/newPage'); 
                      emp.DN_Resignation_Date__c= System.today();           
                      update emp;
                      return null;
                   
                  }
    
}


VF Page: 

<apex:page controller="ResignationButtonClass" >
 <apex:form >
 <apex:commandbutton value="Resign" action="{!Resign}"/>
           
       </apex:form> 
</apex:page>
Hi, 
when button is clicked, the date field should populate as today's date. i am trying in LWC and its doesnt work. please see below code.

HTML:
<template>
   
    <lightning-button
                     class="slds-button slds-button_brand"
                      label="Resignation"
                      variant="brand"
                      onclick={updateDate}>
    </lightning-button>
</template>

JS:

import { LightningElement, api, wire} from 'lwc';
import {getRecord} from 'lightning/uiRecordApi';
import RESIGN_FIELD from '@salesforce/schema/Employee_Information__c.DN_Resignation_Date__c';
const fields = [RESIGN_FIELD];
export default class ResignButton extends LightningElement {
    @api recordId;
    @wire(getRecord, { recordId: '$recordId', fields })
    employee_Information__c;
updateDate(){
    let fields = new Date().toISOString();
}
}
Hi, 

Trying to run the test but for some reason my test code coverage shows None. Here is my code

Class:

public with sharing class emailHelper {
public Aspirant__c asp {get;set;}    
public User myUser { get;set;}

public emailHelper(ApexPages.StandardController stdController)

    asp = (Aspirant__c)stdController.getRecord(); 
}

User currentUser = [Select email from User where username = :UserInfo.getUserName() limit 1];

public  PageReference sendEmail() {
PageReference emailPage = new PageReference('/email/author/emailauthor.jsp');
Map<String, String> params = emailPage.getParameters();
params.put('p2_lkid',asp.Email__c);
params.put('p3_lkid',asp.ID); 
params.put('template_id','00X3K000000F91e'); 
params.put('rtype','003');
params.put('p24',currentUser.Email); 
params.put('new_template','1'); 
params.put('retURL',ApexPages.currentPage().getUrl()); 
     
return emailPage;     
}
}


Test:

@isTest 
public class emailHelperTest
{
 static testMethod void testMethod1() 
 {
 Aspirant__c testAsp = new Aspirant__c();
 testAsp.First_Name__c='Test' ;
 testAsp.Email__c ='tharanginigts@gmail.com';
 insert  testAsp;
 
 Test.startTest();
PageReference emailPage = new PageReference('/email/author/emailauthor.jsp');
Map<String, String> params = emailPage.getParameters();
params.put('p3_lkid',testAsp.ID); //email will be attached to the activity history of the account where the button was clicked using the acct.ID
params.put('template_id','00X3K000000F91e'); /// template ID of the email template to be shown goes here
params.put('rtype','003');
params.put('p24',testAsp.Email__c); //currentUser.Email showing in "Additional to" field
params.put('new_template','1'); 
params.put('retURL',ApexPages.currentPage().getUrl()); //after send button is clicked, go back to the account where the button was clicked
 Test.stopTest();
 }
}
Hi, 
I am trying to create PDF from a HTML Email Template. i have a requirement to create a offer letter as a pdf and send email with pdf attachment to the selected candidate.  
My idea on this requirement is, first create a pdf from HTML Email Template (with all merge fields) and Create custom button on the UI page for sending email. 
Getting Error on Trigger - Unexpected Token 'Account.Parent.Id'

Here is my Code:

trigger RestrictParentAccount on Opportunity (before insert){

list<Opportunity> Opp =  new List<Opportunity>();
    For(Opportunity Opp:trigger.New){
    List<Opportunity> OptyAcc = [Select id From Opportunity WHERE AccountId = Account.Parent.Id];
    {
      If(OptyAcc.size() > 0){
         opp.AddError('Opportunity Cant be created by Parent Account');
    }
  }
}
}

 
i have used seealldata=true for my test class below, its cover 100% and no failure. my question here is can we use seealldata= true for production deployement too? When i remove the sealldata=true in test class, code coverage is 100% but having 130+ failure. see below screenshot. 

Batch Apex:

global class EmailBounceBatchApex implements Database.Batchable<sobject>{
    global Database.QueryLocator start(Database.BatchableContext bc) {
        string query = 'SELECT Id,Name from Lead where EmailBouncedDate!=Null AND EmailBouncedReason!=Null';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<Lead> Scope) {
        for(Lead l:Scope){
            
                l.Status = 'Disqualified';
                l.Reason_for__c = 'Inadequate Data';
                
           }
            update scope;
    
    }
    global void finish(Database.BatchableContext bc) {
                }
}

TestClass:

@isTest
public class EmailBounceBatchApexTest {
    Public Static testmethod void BounceTest() {      
        Lead testLead = new Lead();
        testLead.LastName = 'Test';
        testLead.Company ='ABC';
        testLead.Email='trd@gmail.com';
        testLead.Phone='1234567890';
        insert testLead;
   
        testLead.EmailBouncedDate = system.today();
        testLead.EmailBouncedReason ='email address was not valid';
        update testLead;
        
       Campaign camp1 = new Campaign();
        camp1.Name = 'Test Campaign 1';
        camp1.IsActive = True;
        insert camp1;
      
      CampaignMember testMember = new CampaignMember(LeadId =testLead.Id, CampaignId =camp1.id, Status = 'Sent');
        insert testMember;
        EmailBounceBatchApex bc = new EmailBounceBatchApex();
        database.executeBatch(bc);
            
        }
}



User-added image
Getting this error on my test class: System.QueryException: List has no rows for assignment to SObject. line 18
Batch Apex:

Batch apex working fine, but in test class trying to add lead to campaign. 

global class EmailBounceBatchApex implements Database.Batchable<sobject>{
    global Database.QueryLocator start(Database.BatchableContext bc) {
        string query = 'SELECT Id,Name from Lead where EmailBouncedDate!=Null AND EmailBouncedReason!=Null';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<Lead> Scope) {
        for(Lead l:Scope){
            
                l.Status = 'Disqualified';
                l.Reason_for__c = 'Inadequate Data';
                System.Debug(l.status);
           }
            update scope;
    
    }
    global void finish(Database.BatchableContext bc) {
                }
}

Test Class:
 @isTest(SeeAllData=true)
public class EmailBounceBatchApexTest {
    Public Static testmethod void BounceTest() {
        
       
        Lead testLead = new Lead();
        testLead.LastName = 'Test';
        testLead.Company ='ABC';
        testLead.Email='trd@gmail.com';
        testLead.Phone='1234567890';
        insert testLead;
        
       Campaign camp1 = new Campaign();
        camp1.Name = 'Test Campaign 1';
        camp1.IsActive = True;
        insert camp1;
        
        Campaign campID = [SELECT Id FROM Campaign WHERE Name = 'Test Campaign 1'
                           AND IsActive = True AND CreatedDate = :System.today() ];
      
      CampaignMember testMember = new CampaignMember(LeadId =testLead.Id, CampaignId ='campID', Status = 'Sent');
        insert testMember;
            
        }
}
Here is my Code: 

public class LeadEmailBounce {
    @InvocableMethod 
    public static void Bounce(){
      
      List<Lead> L1 = [SELECT EmailBouncedDate,EmailBouncedReason,Id,Name FROM Lead];
      List<Lead> L2 = new List<Lead>();
      for(Lead Leads:L1) {
        
       If (Leads.EmailBouncedDate!=Null && Leads.EmailBouncedReason!=Null)
       {
            Leads.Status = 'Disqualified';
            Leads.Reason_for__c = 'Inadequate Data';
              L2.add(Leads);
          
    }
        update L2;
    }
}
}

Test Class: 
@istest
public class LeadEmailBounceTest {

    Public Static testmethod void BounceTest() {
        
        Lead L1 = new Lead();
        L1.lastname ='Test';
        L1.Email ='thara@gail.com';
        L1.Phone = '0123456789';
        L1.Company ='ABC';
       
        
        Test.startTest();
        Database.SaveResult result = Database.insert(L1, true);
        Test.stopTest();
     
        list<lead> le = [select Id,Email from Lead];
        integer i=le.size();
        system.assertEquals(1,i); 
        
  }
}
Getting this error on test class  " Method does not exist or incorrect signature: void sendEmail(Id, Id) from the type LeadEmailBounce"

Here is my Apex Code: 

public class LeadEmailBounce {
    @InvocableMethod 
    public static void Bounce(){
      
      List<Lead> L1 = [SELECT EmailBouncedDate,EmailBouncedReason,Id,Name FROM Lead];
      List<Lead> L2 = new List<Lead>();
      for(Lead Leads:L1) {
        
       If (Leads.EmailBouncedDate!=Null && Leads.EmailBouncedReason!=Null)
       {
            Leads.Status = 'Disqualified';
            Leads.Reason_for__c = 'Inadequate Data';
              L2.add(Leads);
          
    }
        update L2;
    }
}
}


Test Class: 

@istest
public class LeadEmailBounceTest {

    Public Static testmethod void BounceTest() {
        
        Lead L1 = new Lead();
        L1.lastname ='Test';
        L1.Email ='thara@gail.com';
        insert L1;
        
        Lead L2 = new Lead();
        L2.lastname='Test2';
        L2.Email ='thar@gail.com';
        insert L2;
   
      
          LeadEmailBounce.sendEmail(L1.id, L2.id);
            
    }
}
        
        
        




 
Requirement: 
SOQL:  
1.account rating = prospect   
2.account didn't have any opportunities last 2 years
3.account didn't have any tasks last 2 years    
Action: 
get this related account details and contact details   
1.update account rating as dormant 

Batch Class:

global class opptask implements Database.Batchable <sobject>{ public List <Account> acclist = new List <Account>();
public List <id> taskList = new List<id>();
global Database.QueryLocator start(Database.BatchableContext bc) { string query = 'SELECT accountid FROM Task WHERE What.Type = Account AND CreatedDate = LAST_N_MONTHS:48';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Task> scope)
{
for(Task tsk : scope)
{
taskList.add(tsk.whatId);
}
acclist = [SELECT Id, Name FROM account WHERE Rating = 'Prospect' AND Id NOT IN (SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:48) AND Id NOT IN :taskList];
for (Account a : acclist)
{
a.Rating = 'dormant';
}
Update acclist;
}
global void finish(Database.BatchableContext bc) { }
}

Test Class:

@isTest
Private Class opptasktest {

   Static testMethod void testBatchExecuteMethod()
   {
     Account a = new Account();
     a.Name = 'John Smith';
     a.Rating = 'Prospect';

     insert a;

     Test.startTest();

     opptask batchTest = new opptask ();
     Id jobid = Database.executeBatch(batchTest,5);

     Test.stopTest();

     Account acc = [Select Rating from Account where id=: a.Id];

     System.assertEquals('Dormant', acc.Rating);
    }
}
 
Error: Illegal assignment from String to List<Account> 
Requirement: 
SOQL:  
1.account rating = prospect   
2.account didn't have any opportunities last 2 years
3.account didn't have any tasks last 2 years    

Action: 
get this related account details and contact details   
1.update account rating as dormant     

                                                                                                                 
Here is my Code:  
global class opptask implements Database.Batchable <sobject>{
      List <Account> acc = new List<Account>();
      
global Database.QueryLocator start(Database.BatchableContext bc) {
     List <Task> taskList = new List<Task>();
    string query = 'SELECT accountid FROM Task WHERE What.Type = Account AND CreatedDate = LAST_N_MONTHS:48';
      
     return Database.getQueryLocator(query);
      }
global void execute(Database.BatchableContext bc, List<Account> acclist) {
  acclist ='SELECT Id, Name FROM account WHERE Rating = Prospect AND Id NOT IN (SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:48) AND Id NOT IN (taskList)';
         
  for (Account a : acclist) {
        a.Rating = dormant;
        }
   Update acc;
    }
    
    global void finish(Database.BatchableContext bc) {
        
    }
}
Hi, 

I am working on opportunity object, i have created the list view button for new opty creation. The requirement is when we choose the business type custom field which is recordtype field, the record should create with that recordtype and its respective fields. the problem in my lwc code is the record get created but its having only the standard fields and respective fields for recordtype is not there in record. below is my code. 


HTML:
<!--
  @description       :
  @author            : ChangeMeIn@UserSettingsUnder.SFDoc
  @group             :
  @last modified on  : 12-03-2022
  @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
-->
<template>
    <template if:true={isOpen}>
      <c-modal onclose={closeHandler}>
            <template if:true={iscreatenewopty}>
            <lightning-record-edit-form object-api-name="Opportunity" onsuccess={handleSuccess} onerror={handleError}>
                    <lightning-card title="New Opportunity ">
                        <lightning-layout>
                            <lightning-layout-item size="6" padding="around-small">
                                <lightning-card title="Create A New Opportunity ">
                                    <lightning-output-field field-name="OwnerId"></lightning-output-field>
                                    <lightning-input-field field-name="Name"></lightning-input-field>
                                    <lightning-input-field field-name="AccountId"></lightning-input-field>
                                    <lightning-input-field field-name="Working_Month__c" required="true"></lightning-input-field>
                                    <lightning-input-field field-name="Total_Contract_Value__c"></lightning-input-field>
                                    <lightning-input-field field-name="Department__c" required="true"></lightning-input-field>
                                    <lightning-input-field field-name="Term__c"></lightning-input-field>
                                 </lightning-card>
                            </lightning-layout-item>
                            <lightning-layout-item size="6" padding="around-small">
                                <lightning-card >
                                    <lightning-input-field field-name="Business_Type__c"></lightning-input-field>
                                    <lightning-input-field field-name="CloseDate"></lightning-input-field>
                                    <lightning-input-field field-name="StageName"></lightning-input-field>
                                    <lightning-input-field field-name="Forecast_Category__c"></lightning-input-field>
                                    <lightning-input-field field-name="Probability"></lightning-input-field>
                                    <lightning-input-field field-name="Amount"></lightning-input-field>
                                    <lightning-input-field field-name="Contract_duration__c"></lightning-input-field>
                                    <lightning-input-field field-name="Forecast_Category__c"></lightning-input-field>
                                </lightning-card>
                            </lightning-layout-item>
                        </lightning-layout>                              
                    </lightning-card>              
            </lightning-record-edit-form>
            <div slot="footer">
                <button class="slds-button slds-button_brand" onclick={handleSubmitButtonClick}>Save and Create Service</button>
             <lightning-button icon-name="utility:delete" class="slds-p-around_large" variant="destructive" padding="around-large" type="submit" label="cancel" onclick={closeHandler}></lightning-button>
            </div>
        </template>
        <template if:false={iscreatenewopty}>
            <c-create-Opty-Service opportunity-id={opportunityId}>
             </c-create-Opty-Service>
          </template>
         </c-modal>
                </template>
            </template>
Js: 

import { LightningElement,track } from 'lwc';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
export default class CreateNewOpty extends LightningElement {
    @track opportunityId = ''
    isOpen = true  
    iscreatenewopty = true
    openHandler(){
        console.log("Clicked!!")
        this.isOpen = true
    }      
    closeHandler(){
        this.isOpen = false
    }  
    handleClose(event){
        this.rating = '0';
        this.cancel = true;
        this.handleSubmit(event);
    }
    handleSubmitButtonClick(event){  
        event.preventDefault();    
      //  console.log("id of created :"+id)
     
      const fields = this.template.querySelector('lightning-record-edit-form').fields;
      console.log('-----------------------');
      console.log(fields);
        var isVal = true;
        this.template.querySelectorAll('lightning-input-field').forEach(element => {
            isVal = isVal && element.reportValidity();
        });
        if (isVal) {                
            this.template.querySelector('lightning-record-edit-form').submit();    
               
     
        } else {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: 'Please enter all the required fields',
                    variant: 'error',
                }),
            );
        }
     }
     handleSuccess(event) {
        this.opportunityId = event.detail.id;
        console.log("id of created :"+this.opportunityId)
        this.iscreatenewopty=false;
        this.showSuccessNotification(this.opportunityId);
    }
    handleError(event) {
        console.log(JSON.stringify(event.detail))
        this.dispatchEvent(
            new ShowToastEvent({
                title: event.detail.output.errors[0].errorCode,
                message: event.detail.detail,
                variant: 'error',
            }),
        );
    }
    showSuccessNotification(opportunityId){            
        const event = new ShowToastEvent({
            title: "Success",
            message: "Opportunity Created Successfully - "+opportunityId,
            variant:"Success"
        });
        this.dispatchEvent(event);
    }
}
Getting this error for the below apex test class: 

Apex Handler: 
public class InsertIncomeRecordHandler {
    public static void insertRecord(List<Salary_Detail__c> salList,Map<id,Salary_Detail__c> oldMap){
        Set<Id> empId = new Set<Id>();
        List<D_Transaction__c> dList = new List<D_Transaction__c>();
        ID income = Schema.SObjectType.D_Transaction__c.getRecordTypeInfosByName().get('Income').getRecordTypeId();
        ID trans = Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('Transaction').getRecordTypeId();
        ID expense = Schema.SObjectType.D_Transaction__c.getRecordTypeInfosByName().get('Expense').getRecordTypeId();
        
        for(Salary_Detail__c sd : salList){
            if(sd.Advance__c != oldMap.get(sd.Id).Advance__c && sd.Isdetected__c !=oldMap.get(sd.Id).Isdetected__c){
            if(sd.Advance__c >0 && sd.RecordTypeId == trans && sd.Organization__c == 'Deshkal'){
                empId.add(sd.Employee_Information__c);
            }
            }
            
            system.debug(' empIdt' + empId);
        }
        
      
        for(Employee_Information__c emp : [select id,Name From Employee_Information__c where id IN :empId]){
        for(D_Transaction__c dt : [SELECT RecordTypeId,D_Amount__c,D_Employee__c,D_Advance_Status__c,D_Advance_Repay__c,D_Name__c FROM D_Transaction__c where D_Employee__c =:emp.Id AND RecordTypeId =:expense AND D_Advance_Status__c = 'Open' ]){
            
                D_Transaction__c d = new D_Transaction__c();
                d.D_Employee__c = emp.Id;
                d.RecordTypeId = income;
                d.D_Transaction__c =dt.Id;
                Integer result = integer.valueOf(dt.D_Amount__c) / integer.valueOf(dt.D_Advance_Repay__c);
                d.D_Amount__c = result;
                system.debug('d.D_Amount__c');
                dList.add(d);
            
        }
        }
        
        if(!dList.isEmpty()){
            insert dList;
        }
    }
}


Test Class:
@isTest
private class InsertIncomeRecordHandlerTest {

    @isTest
    static void testInsertRecord() {
        // Create test data
        Employee_Information__c emp = new Employee_Information__c();
        emp.Salutation__c = 'Mr.';
        emp.Name = 'Test';
        emp.Employee_Last_Name__c = 'HR Admin';
        emp.Date_of_Join__c = system.today();
        emp.Gender__c = 'Male';
        emp.Personal_Email__c = 'abc@gmail.com';
        emp.Marital_Status__c = 'Single';
        emp.Employment_Status__c = 'Active';
        emp.DN_Designation__c='CEO';
        emp.Date_of_Birth__c=Date.newInstance(2000, 12, 9);
        emp.Gender__c='Male';
        emp.Manager_Supervisor__c = 'Deepu H D';
        emp.Work_Location__c = 'NOC';
        emp.Bank_Name__c='HDFC';
        emp.Account_Number__c='12345678901234';
        emp.Mobile_Number__c='9999999999';
        emp.IFSC_CODE__c='HDFC0000003';
        emp.Confirmed_CTC__c=800000;
        emp.Basic_Percentage__c='40';
        emp.Tax_Regime__c='Old Regime';
       emp.PFs__c='Percentage';
        emp.Marital_Status__c='Single';
        emp.Aadhaar_Number__c='265385644663';
        emp.Address__c='Test';
        emp.City__c='Chennai';
       emp.Organization__c='Deshkal';
        emp.Postal_Code__c='600001';
      emp.DN_Leave_Process__c='Yes';
        insert emp;

        Salary_Detail__c salary = new Salary_Detail__c(
            Employee_Information__c = emp.Id,
            RecordTypeId = Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('Transaction').getRecordTypeId(),
            Advance__c = 60,
            Isdetected__c = false,
            Organization__c = 'Deshkal'
        );
        insert salary;

        
      D_Transaction__c dt = new D_Transaction__c ();
             dt.D_Employee__c = emp.Id;
        dt.D_Amount__c = 100;
            dt.D_Advance_Repay__c =' 12';
            dt.RecordTypeId = Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('expense').getRecordTypeId();
        dt.D_Advance_Status__c = 'Open';
                
                               
                     

       
        Test.startTest();
insert dt;
        Test.stopTest();
        
      }
        



}
 
Hi, 
I am trying to create PDF from a HTML Email Template. i have a requirement to create a offer letter as a pdf and send email with pdf attachment to the selected candidate.  
My idea on this requirement is, first create a pdf from HTML Email Template (with all merge fields) and Create custom button on the UI page for sending email. 
Getting Error on Trigger - Unexpected Token 'Account.Parent.Id'

Here is my Code:

trigger RestrictParentAccount on Opportunity (before insert){

list<Opportunity> Opp =  new List<Opportunity>();
    For(Opportunity Opp:trigger.New){
    List<Opportunity> OptyAcc = [Select id From Opportunity WHERE AccountId = Account.Parent.Id];
    {
      If(OptyAcc.size() > 0){
         opp.AddError('Opportunity Cant be created by Parent Account');
    }
  }
}
}

 
Getting this error on my test class: System.QueryException: List has no rows for assignment to SObject. line 18
Batch Apex:

Batch apex working fine, but in test class trying to add lead to campaign. 

global class EmailBounceBatchApex implements Database.Batchable<sobject>{
    global Database.QueryLocator start(Database.BatchableContext bc) {
        string query = 'SELECT Id,Name from Lead where EmailBouncedDate!=Null AND EmailBouncedReason!=Null';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<Lead> Scope) {
        for(Lead l:Scope){
            
                l.Status = 'Disqualified';
                l.Reason_for__c = 'Inadequate Data';
                System.Debug(l.status);
           }
            update scope;
    
    }
    global void finish(Database.BatchableContext bc) {
                }
}

Test Class:
 @isTest(SeeAllData=true)
public class EmailBounceBatchApexTest {
    Public Static testmethod void BounceTest() {
        
       
        Lead testLead = new Lead();
        testLead.LastName = 'Test';
        testLead.Company ='ABC';
        testLead.Email='trd@gmail.com';
        testLead.Phone='1234567890';
        insert testLead;
        
       Campaign camp1 = new Campaign();
        camp1.Name = 'Test Campaign 1';
        camp1.IsActive = True;
        insert camp1;
        
        Campaign campID = [SELECT Id FROM Campaign WHERE Name = 'Test Campaign 1'
                           AND IsActive = True AND CreatedDate = :System.today() ];
      
      CampaignMember testMember = new CampaignMember(LeadId =testLead.Id, CampaignId ='campID', Status = 'Sent');
        insert testMember;
            
        }
}
Error: Illegal assignment from String to List<Account> 
Requirement: 
SOQL:  
1.account rating = prospect   
2.account didn't have any opportunities last 2 years
3.account didn't have any tasks last 2 years    

Action: 
get this related account details and contact details   
1.update account rating as dormant     

                                                                                                                 
Here is my Code:  
global class opptask implements Database.Batchable <sobject>{
      List <Account> acc = new List<Account>();
      
global Database.QueryLocator start(Database.BatchableContext bc) {
     List <Task> taskList = new List<Task>();
    string query = 'SELECT accountid FROM Task WHERE What.Type = Account AND CreatedDate = LAST_N_MONTHS:48';
      
     return Database.getQueryLocator(query);
      }
global void execute(Database.BatchableContext bc, List<Account> acclist) {
  acclist ='SELECT Id, Name FROM account WHERE Rating = Prospect AND Id NOT IN (SELECT accountid FROM Opportunity WHERE CreatedDate = LAST_N_MONTHS:48) AND Id NOT IN (taskList)';
         
  for (Account a : acclist) {
        a.Rating = dormant;
        }
   Update acc;
    }
    
    global void finish(Database.BatchableContext bc) {
        
    }
}