• Mona Kawale
  • NEWBIE
  • 5 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 2
    Replies
Hi,
I am sending an email through apex class to users. Email is going from (noreply@salesforce.com; on behalf of; XXX <xxx@xxx.com>.) But this is not working for only one profile.
I have connected 2 salesforce org using integration. Now If I want to insert records in one org , they should automatically get copied into another org. So how to achieve this?
HTML FILE

<template>
    <lightning-card title="Contacts Of Account">
        <div class="slds-p-around_medium">
         <lightning-input
         type="text"
         value={account}
         label="Enter Account Name"
         onkeyup={textHandler}></lightning-input>
       
         <lightning-button
         label="Search"
         size="small" variant="brand"
         onclick={handleAccountSearch} ></lightning-button>
       
        <h2>Account Name :- <span><strong>{currentAccName}</strong></span></h2><br/>
        <table class="slds-table slds-table_cell-buffer slds-table_bordered"
        border="1" cellspacing="0" cellpadding="0"
        style="border-collapse:collapse">
            <thead>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>Account Name</th>
                </tr>
            </thead>
            <tbody>
                <template if:true={accounts}>
                <template for:each={accounts} for:item="account">
                    <tr key={account.Name}>
                        <td>{account.FirstName}</td>
                        <td>{account.LastName}</td>
                        <td>{account.Email}</td>
                        <td>{account.Phone}</td>
                        <td>{account.Account.Name}</td>
                    </tr>
                </template>
            </template>
            </tbody>
        </table>
        </div>
    </lightning-card>
</template>


JS FILE


import { LightningElement ,track,wire} from 'lwc';
import ConMethod from '@salesforce/apex/AccountController.ConMethod'
export default class FindContactOfAccount extends LightningElement {
     searchKey =''
    @track searchAccName
    @track currentAccName
    @track accounts
    textHandler(event){
        this.currentAccName=event.target.value
    }
    handleAccountSearch(){
  this.searchKey=target.currentAccName
    ConMethod({searchKey:this.searchKey})
    .then((result)=>{
     this.accounts=result;
     this.error = undefined;
   }).catch((error)=>{
    this.error = error;
    this.contacts = undefined;  
 });
}
}

Class File

public with sharing class AccountController {
    @AuraEnabled(cacheable=true)
    public static list<Account> getAccountList(){
        return[SELECT Id, Name, Type, Industry from Account where Industry!=Null LIMIT 6];
     }
     @AuraEnabled(cacheable=true)
    public static list<Account> filterAccountbyType(String type){
        return[SELECT Id, Name, Type from Account where type=: type LIMIT 6];
     }
     @AuraEnabled(cacheable=true)
    public static list<Account> findAccounts(String searchKey){
        String key='%'+ searchKey +'%';
        return[SELECT Id, Name, Type, Industry, (Select Id, Lastname from Contacts) from Account where Name like :key LIMIT 6];
     }
      @AuraEnabled(cacheable=true)
        public static list<Account> AccMethod(){
        list<Account> Acclist=[SELECT Id, Name, Type, Industry from Account];
        return Acclist;
     }
     @AuraEnabled(cacheable=true)
        public static list<Contact> ConMethod(String searchKey){
        list<Contact> ConList=[SELECT Id, FirstName,LastName,Email,Phone,  Account.Name from Contact where Account.Name=:searchKey];
        return ConList;
     }
   }

In output, when I click on search button ,contacts of accounts are not showing.

Please Answer
//If I am inserting account then it should make count with 
//respect to its number of same account with same name count in Org.
public class CountDuplicateAccount {
    
    
    public static void myMethod(List<Account> newList){
        integer count=0;
        set<id> ids=new set<id>();
        for(account ac:newlist){
            ids.add(ac.id);
        }
        map<id,Account> oldlist = new map<id, account>([select id, name from Account where id In: ids]);
        
        if(!newList.isempty()){
            for(Account acc:newList){
                if(acc.name==oldlist.get(acc.id).name)
                    count=count+1;
                acc.Total_Duplicate_Account__c=count+1;
                
                
                
            }
        }
        
        
    }
    
}
//when ever new record create into account object before this new record
//is inserted into account delete all contact record with this account name
Trigger 
trigger ContactttTrigger on Contact (after insert, after update) {
     if(trigger.isinsert || trigger.isupdate && trigger.isafter){
        ContactHandler.mymethod(trigger.new);
    }

}

Handler Class
public class ContactHandler {
    
    public static void mymethod(list<contact> conlist){
        list<Contact_Relationship__c> contlist=new list<Contact_Relationship__c>();
        for(contact con:conlist){
                        
            if(con.Contact_Relationship__c==true){
                Contact_Relationship__c CR=new Contact_Relationship__c();
                CR.name=con.lastname;
                cr.Contact__c=con.id;
                contlist.add(cr);
            }
        }
        if(!contlist.isempty()){
            insert contlist;}
        
    }
}

Test Class
@istest
public class ContacttttTest {
    @istest
    public static void testme(){
        
        Contact con=new contact();
        con.lastname='Jack';
        con.Contact_Relationship__c=true;
        insert con;
        
        Contact con1=new contact();
        con1.lastname='Ma';
        con1.Contact_Relationship__c=false;
        insert con1;
        
        
        list<contact> conlist=[select id, Lastname, Contact_Relationship__c from contact];
        Test.startTest();
        ContactHandler.mymethod(conlist);
        Test.stopTest();
        System.assertEquals(1, [select count() from Contact_Relationship__c where name='Mona']);
    }
    
}


 
Create an Object Employee: Name, Project Name, Start date, end date, Status (Available, Busy) Create a child object Contract with Project name, start date, end date, employee (lookup) , primary ( check box ) (Here you have to write trigger) as soon as new contract is created under an employee, employee record should get updated ( Start date, end date, Status) If that employee already have another active contract then based on primary contract, data should get updated on Employee
//If I am inserting account then it should make count with 
//respect to its number of same account with same name count in Org.
public class CountDuplicateAccount {
    
    
    public static void myMethod(List<Account> newList){
        integer count=0;
        set<id> ids=new set<id>();
        for(account ac:newlist){
            ids.add(ac.id);
        }
        map<id,Account> oldlist = new map<id, account>([select id, name from Account where id In: ids]);
        
        if(!newList.isempty()){
            for(Account acc:newList){
                if(acc.name==oldlist.get(acc.id).name)
                    count=count+1;
                acc.Total_Duplicate_Account__c=count+1;
                
                
                
            }
        }
        
        
    }
    
}