• Anshii
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
Hi every one,using lwc i am able to navigate to the detailpage but unable to open the new form when i click on new booking  getting errors in js file,please help me out.

Thanks in Advance.

html:
-----------

<template>
<!-- <lightning-card title="All Bookings">
<div class="slds-p-around_medium">
<template if:true={contacts} for:each={contacts} for:item="contact">
<li key={contact.Id}>
<a>{contact.Name}</a>
</li>
</template>
</div>
</lightning-card>-->
<lightning-card title="title of the component" class="slds-clearfix">
<div class="slds-p-around_medium">
<div class="slds-float_left"> <template if:true={bookings} for:each={bookings} for:item="booking">
<li key={booking.Id}>
<a target="_blank" onclick={handleOnClick} data-target-id={booking.Id}>{booking.Name}</a>
</li>
</template>
</div>
</div>
<div class="slds-clearfix">
<div class="slds-float_right">
<lightning-button label="New Booking" class="slds-m-left_x-small" onclick={navigatetorecordpage}></lightning-button>
</div>
</div>
</lightning-card>
</template>
-------
js:
import { LightningElement,api,track,wire } from 'lwc';
import getBookingList from '@salesforce/apex/taskexample.getBookingList';
 
import {NavigationMixin} from 'lightning/navigation';
 

   export default class lwcTask extends NavigationMixin (LightningElement) {  
    bookings;
error;


@wire(getBookingList) bookingDetails({error,data}){
if(data){
this.bookings=data;
}
else if(error){
this.error=error;
}
}


handleOnClick(event){
event.preventDefault();


let _recordId=event.target.dataset.targetId;

navigatetorecordpage( ){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: _recordId,
objectApiName: 'Bokking__c',
actionName: 'New',
}
});
}
}
   }


 
  • March 21, 2022
  • Like
  • 0
Hi Everyone, below is the code am able to cover 91 % of codecoverage unable to cover the return statements in test class.plz helpme out

Thanks in Advance.
paginationclass:
public class Diplayaccrelatecon {
    private integer totalRecs = 0;      
    private integer index = 0;
    private integer blockSize = 5;
   
   // public boolean prev {get; set;}
    //public boolean nxt {get;set;}
    //public boolean frt {get;set;}
    //public boolean sec{get;set;}
   
    //public List<Account> accList{get;set;}
   public list<Contact> conList{get;set;}
   public String accId{get;set;}
   
  public Diplayaccrelatecon() {
        totalRecs = [select count() from Account];        
    }        
    public List<Account> getacc() {//get will take the value from apex to vf
        List<Account> accs = Database.Query('SELECT id,name,phone FROM Account LIMIT :blockSize');//queried dynamically as string
        System.debug('Values are ' +accs);
        return accs;
    }          
    public void first() {
        index = index - blockSize;
        getacc();
    }     
    public void second() {
        index = index + blockSize;
       getacc();
    }
    public void save(){
        update conList;
    }
    public boolean getdisablefrt() {
        if(index == 0)
            return true;
        else
            return false;
    }      
    public boolean getdisablesec() {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }       
       public PageReference dispalyContact() {
       system.debug('accId'+accId);        
         if(accId != null)             
         if(index>=0)      
  {
      conList=[SELECT id,Name,FirstName,LastName,email FROM Contact WHERE AccountId=:accId LIMIT:blockSize ];
  }          system.debug('conList'+conList);   
             return null;       
 }     
        
    public void previous() {
        index = blockSize - index;
        dispalyContact();
    }     
    public void next() {
        index = index + blockSize;
         dispalyContact();
    }            
             
    public boolean getdisableprev() {
        if(index == 0)
            return true;
        else
            return false;
    }       
    public boolean getdisablenxt() {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }     
}
Testclass:
@isTest
public class DisplayaccrelTestclass {
   
         
@isTest
    static void call(){
         integer totalRecs = 0;     
     integer index = 0;
     integer blockSize = 5;    
        Account a=new Account();
        a.name='testacc';
        a.phone='testphone';
        insert a;
        contact c=new contact();
        c.firstName='testfirstName';
        c.LastName='testLastName';
        c.Email='test@gmail.com';
        c.AccountId=a.id;
        insert c;
        system.debug('1:'+c);
         
        Test.startTest();
        
         Diplayaccrelatecon d = new Diplayaccrelatecon ();
        //d.index=0;
        d.first();
        d.second();
       
        d.getdisablefrt();
        d.getdisablesec();
       d.next();
        d.previous();
        
       
        d.getacc();    
        c.AccountId=a.id;
        system.debug('2:'+a.id);
        contact con=[select id,Accountid from contact];
        
        system.assertEquals(con.Accountid, a.id);
       d.accId=a.id;
       d.dispalyContact();
         d.save();
       // d.getdisableprev();
        d.getdisablenxt();
        Test.stopTest();
    }
    @isTest 
    static void show(){
        integer totalRecs = 15;     
     integer index = 1;
     integer blockSize = 5; 
        Test.startTest();
        Diplayaccrelatecon ds=new Diplayaccrelatecon();
        //system.assertEquals(false, ds.getdisablefrt());
        ds.getdisablefrt();
        //system.assertEquals(false, ds.getdisablesec());
       // ds.index=5;
        ds.getdisablesec();
        ds.getdisableprev();
        ds.getdisablenxt();
        Test.stopTest();
    }
}
Hi everyone,
my scenario is to insert an account  record  to the particular user which  i have created in my org .and that account has only read access.how to insert an account record to particular user using apex can some one help.
when i login as that user i need to see  the record which i have inserted.

Thanks in Advance.
Hi everyone , I have written a trigger so for for submitting a record for approval.i need to set the trigger to approval automatically please help me out.
Trigger:1

trigger contactcreated on Contact (after insert) {
    for(contact c : trigger.new){
        if(c.isprimary__c == True){
            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(c.Id);
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
        }
    }
}
Trigger2:
trigger Contactcreatedapprocess on Contact (after insert) {
     user u1=[select id from user where alias='anshu'];
    for(contact c:Trigger.new){
        if(c.isprimary__c==true){
        //step1:create a approval req to submit
       Approval.ProcessSubmitRequest req=new Approval.ProcessSubmitRequest();
        req.setComments('submitted for approval please submit');
        req.setObjectId(c.Id);
        req.setSubmitterId(u1.id);
       //submit the request for approval
      Approval.ProcessResult result=Approval.process(req);
    }
    }
}

Thanks in Advance
Hi Everyone ,
myscenario is display the inputfeilds from vf page using customcontroller onpageload the fields should populate and  byclicking on button ,page should be shown as pdf .please help me out with an example

Thanks in Advance.
Hi All,my scenario is to display the feild values(in InputField) from vf on pageload also populate some fields  in outputText ,and when I click on Button the values which are populated should shown as pdf format.

I have tried so far using lookup ,Below code which i have wrote.But without using lookup onload of the vf page the values should populate .whatever the populated values should shown as pdf format when i click on button..please helpme out .
Thanks in Advance.

class:
public class AccountcontrollerExample {
    public contact c{set;get;}
    public AccountcontrollerExample(Apexpages.StandardController stdcontroller){
        c=(contact)stdcontroller.getRecord();
    }
    public void show(){
        Account acc=[select id,name,phone,Description from Account where id=:c.accountid];
                   c.Description=acc.Description;
                    c.Assistantphone=acc.Phone;
        
        
    }
        }
vf:
<apex:page standardcontroller="contact" extensions="AccountcontrollerExample">
    <apex:form >
        <apex:actionFunction name="Autopopulate" action="{!show}"/>
        <apex:pageBlock title="myInfo" tabStyle="Account">
            <apex:pageBlockSection title="AccCon Info" collapsible="false">
                <apex:inputField value="{!c.AccountId}" onchange="Autopopulate()"/>
                <apex:outputText value="{!c.Description}"/>
                <apex:outputText value="{!c.Assistantphone}"/>
            </apex:pageBlockSection>
           <!---          <apex:pageBlocksection>
                <apex:commandLink value="pdf" action="/apex/AccountcontrollerExample?isPdf=true"/>
            </apex:pageBlocksection>-->
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 
Hi every one,using lwc i am able to navigate to the detailpage but unable to open the new form when i click on new booking  getting errors in js file,please help me out.

Thanks in Advance.

html:
-----------

<template>
<!-- <lightning-card title="All Bookings">
<div class="slds-p-around_medium">
<template if:true={contacts} for:each={contacts} for:item="contact">
<li key={contact.Id}>
<a>{contact.Name}</a>
</li>
</template>
</div>
</lightning-card>-->
<lightning-card title="title of the component" class="slds-clearfix">
<div class="slds-p-around_medium">
<div class="slds-float_left"> <template if:true={bookings} for:each={bookings} for:item="booking">
<li key={booking.Id}>
<a target="_blank" onclick={handleOnClick} data-target-id={booking.Id}>{booking.Name}</a>
</li>
</template>
</div>
</div>
<div class="slds-clearfix">
<div class="slds-float_right">
<lightning-button label="New Booking" class="slds-m-left_x-small" onclick={navigatetorecordpage}></lightning-button>
</div>
</div>
</lightning-card>
</template>
-------
js:
import { LightningElement,api,track,wire } from 'lwc';
import getBookingList from '@salesforce/apex/taskexample.getBookingList';
 
import {NavigationMixin} from 'lightning/navigation';
 

   export default class lwcTask extends NavigationMixin (LightningElement) {  
    bookings;
error;


@wire(getBookingList) bookingDetails({error,data}){
if(data){
this.bookings=data;
}
else if(error){
this.error=error;
}
}


handleOnClick(event){
event.preventDefault();


let _recordId=event.target.dataset.targetId;

navigatetorecordpage( ){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: _recordId,
objectApiName: 'Bokking__c',
actionName: 'New',
}
});
}
}
   }


 
  • March 21, 2022
  • Like
  • 0
Hi Everyone, below is the code am able to cover 91 % of codecoverage unable to cover the return statements in test class.plz helpme out

Thanks in Advance.
paginationclass:
public class Diplayaccrelatecon {
    private integer totalRecs = 0;      
    private integer index = 0;
    private integer blockSize = 5;
   
   // public boolean prev {get; set;}
    //public boolean nxt {get;set;}
    //public boolean frt {get;set;}
    //public boolean sec{get;set;}
   
    //public List<Account> accList{get;set;}
   public list<Contact> conList{get;set;}
   public String accId{get;set;}
   
  public Diplayaccrelatecon() {
        totalRecs = [select count() from Account];        
    }        
    public List<Account> getacc() {//get will take the value from apex to vf
        List<Account> accs = Database.Query('SELECT id,name,phone FROM Account LIMIT :blockSize');//queried dynamically as string
        System.debug('Values are ' +accs);
        return accs;
    }          
    public void first() {
        index = index - blockSize;
        getacc();
    }     
    public void second() {
        index = index + blockSize;
       getacc();
    }
    public void save(){
        update conList;
    }
    public boolean getdisablefrt() {
        if(index == 0)
            return true;
        else
            return false;
    }      
    public boolean getdisablesec() {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }       
       public PageReference dispalyContact() {
       system.debug('accId'+accId);        
         if(accId != null)             
         if(index>=0)      
  {
      conList=[SELECT id,Name,FirstName,LastName,email FROM Contact WHERE AccountId=:accId LIMIT:blockSize ];
  }          system.debug('conList'+conList);   
             return null;       
 }     
        
    public void previous() {
        index = blockSize - index;
        dispalyContact();
    }     
    public void next() {
        index = index + blockSize;
         dispalyContact();
    }            
             
    public boolean getdisableprev() {
        if(index == 0)
            return true;
        else
            return false;
    }       
    public boolean getdisablenxt() {
        if((index + blockSize) > totalRecs)
        return true;
        else
        return false;
    }     
}
Testclass:
@isTest
public class DisplayaccrelTestclass {
   
         
@isTest
    static void call(){
         integer totalRecs = 0;     
     integer index = 0;
     integer blockSize = 5;    
        Account a=new Account();
        a.name='testacc';
        a.phone='testphone';
        insert a;
        contact c=new contact();
        c.firstName='testfirstName';
        c.LastName='testLastName';
        c.Email='test@gmail.com';
        c.AccountId=a.id;
        insert c;
        system.debug('1:'+c);
         
        Test.startTest();
        
         Diplayaccrelatecon d = new Diplayaccrelatecon ();
        //d.index=0;
        d.first();
        d.second();
       
        d.getdisablefrt();
        d.getdisablesec();
       d.next();
        d.previous();
        
       
        d.getacc();    
        c.AccountId=a.id;
        system.debug('2:'+a.id);
        contact con=[select id,Accountid from contact];
        
        system.assertEquals(con.Accountid, a.id);
       d.accId=a.id;
       d.dispalyContact();
         d.save();
       // d.getdisableprev();
        d.getdisablenxt();
        Test.stopTest();
    }
    @isTest 
    static void show(){
        integer totalRecs = 15;     
     integer index = 1;
     integer blockSize = 5; 
        Test.startTest();
        Diplayaccrelatecon ds=new Diplayaccrelatecon();
        //system.assertEquals(false, ds.getdisablefrt());
        ds.getdisablefrt();
        //system.assertEquals(false, ds.getdisablesec());
       // ds.index=5;
        ds.getdisablesec();
        ds.getdisableprev();
        ds.getdisablenxt();
        Test.stopTest();
    }
}
Hi everyone,
my scenario is to insert an account  record  to the particular user which  i have created in my org .and that account has only read access.how to insert an account record to particular user using apex can some one help.
when i login as that user i need to see  the record which i have inserted.

Thanks in Advance.
Hi Everyone ,
myscenario is display the inputfeilds from vf page using customcontroller onpageload the fields should populate and  byclicking on button ,page should be shown as pdf .please help me out with an example

Thanks in Advance.