• Vidya H 4
  • NEWBIE
  • 80 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 20
    Replies

 

Need to create list view for Account object, i need to filter records based on "Account name" field.

The problem is
if 2 accounts has same name it will display all records that belong to 2 user.
How to avoid this?
it should display records belong to particular Account name.
and if 2 account names are same it should not display all records
 

Need to trigger with handler class.

I have a text field on Account that is "Primary contact"(text field)  where you will give the related contact name of that particular account, which ever contact name is given in that field shouldn't be able to delete by any user.
ex - if account A has 2 related contacts i.e, c1 and c2.
now i will update that Primary contact field with related contact c1.
now any user should not be able to delete that C1 related contact.
This page has an error. You might just need to refresh it. [Cannot read properties of undefined (reading 'label')] Failing descriptor: {markup://lightning:radioGroup}
how to resolve this
 

  for example - if Account has 3 related contacts such as contact a, contact b and Primary contact.
The contact with name primary contact should not be deleted by any user. Remaning contacts can be deleted.
Please anbody help me to write handler class??

trigger OppValidation on Opportunity (before insert,before update) {
    
    Id profileId= userinfo.getProfileId();
    String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
    if(Trigger.isupdate){
        for(Opportunity opp:Trigger.new){
            opportunity oldoppy= Trigger.oldmap.get(opp.id);
            
            if(opp.Active__c ==false && oldoppy.Active__c==True && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
        
    }
    
    if(Trigger.isinsert){
        for(Opportunity opp:Trigger.new){
            
            if(opp.Active__c ==false && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
    }
}
I have picklist field "Funding" on Quote object and text field "Funding" on Opportunity object. I want to copy the picklist values from all Quotes related to the Opportunity and display it on "Funding" field on Opportunity separated by comma. I tried this code but not working, 

I need to use string join instead of split. please help

global class UpdateFunding implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
    }

    global void execute(Database.BatchableContext context, List<sObject> batch){
        Set<Id> Opportuniyids = new Set<Id>();

        for (sObject oppy : batch) {
            Opportuniyids.add(oppy.Id);
        }

        updatequote(Opportuniyids);
    }

    global void finish(Database.BatchableContext context) {}

    public void updatequote(set<id> oppyids){
        system.debug('opportuiy ids'+oppyids);
        List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
        for(Opportunity opp:opportunities) {
       Set<String> systems = new Set<String>();
        for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
        if (String.isNotBlank(oppObj.Funding__c)) {
            systems.addAll(oppObj.Funding__c.split(';'));
        }
            System.debug('ccc'+systems);
    }
    String accountSystems = '';
    for (String value : systems) {
        accountSystems += value + ';';
    }
    accountSystems = accountSystems.removeEnd(';');
    try {
        update new Opportunity(Id = opp.id,Funding__c  = accountSystems);
    } catch (Exception e) {
        System.debug('Exception: ' + e.getMessage());
    }
        }       
    }

}
global class UpdateFunding implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
    }

    global void execute(Database.BatchableContext context, List<sObject> batch){
        Set<Id> Opportuniyids = new Set<Id>();

        for (sObject oppy : batch) {
            Opportuniyids.add(oppy.Id);
        }

        updatequote(Opportuniyids);
    }

    global void finish(Database.BatchableContext context) {}

    public void updatequote(set<id> oppyids){
        system.debug('opportuiy ids'+oppyids);
        List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
        for(Opportunity opp:opportunities) {
       Set<String> systems = new Set<String>();
        for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
        if (String.isNotBlank(oppObj.Funding__c)) {
            systems.addAll(oppObj.Funding__c.split(';'));
        }
    }
    String accountSystems = '';
    for (String value : systems) {
        accountSystems += value + ';';
    }
    accountSystems = accountSystems.removeEnd(';');
    try {
        update new Opportunity(Id = opp.id,Funding__c  = accountSystems);
    } catch (Exception e) {
        System.debug('Exception: ' + e.getMessage());
    }
        }       
    }

}
I have Created a field called Funding on Quote with values - Partial , Full and NA .
and i Created a field called Funding on Opportunity.
Write a batch class to rollup the unique funding field values from Quote to Opportunity if Opportunity stage is closed/won. Ex: if an opportunity has 6 quotes with funding Full, Full, NA, Partial ,NA, Partial then field on opportunity should be in format - Partial,Full,NA.
trigger AccountStage on Account (After Update) {
    
    Set<Id> accountIds = new Set<Id>();

    for(Account ac : Trigger.new)
    {
         if(ac.Stage__c =='Closed')
              accountIds.add(ac.Id);
    }

     List<Opportunity> oppsToUpdate = new List<Opportunity>();

     for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds])
     {
          opp.StageName='Closed - won';
          opp.closeDate=Date.today();
          oppsToUpdate.add(opp);
     }

     update oppsToUpdate;

}
trigger OppValidation on Opportunity (before insert,before update) {
    
    Id profileId= userinfo.getProfileId();
    String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
    if(Trigger.isupdate){
        for(Opportunity opp:Trigger.new){
            opportunity oldoppy= Trigger.oldmap.get(opp.id);
            
            if(opp.Active__c ==false && oldoppy.Active__c==True && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
        
    }
    
    if(Trigger.isinsert){
        for(Opportunity opp:Trigger.new){
            
            if(opp.Active__c ==false && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
    }
}
I have Created a field on Account called Stage with values - In Progress, Closed. If the stage is changed to closed the trigger should auto update stage of all opportunities for that account to closed/won and close date to current day.
I created a checkbox field call active on opportunity . If a user other than system administrator tries to update the field to inactive when the stage field value is not closed/won show an error 'You do not have the access to perform this operation. Kindly contact your system administrator'
 If installed products and locations don't have preferred technicians, a check is
performed on the Primary Territory of Work order to get the technicians who
have the same territory mentioned in their Service Territory and assign that technician to preferred technician field in work order.

Primary Territory is field in work order (look up to territory)
Service Territory is field in Technician (look up to territory)
installed products and locations are look up fields in work order
preferred technician field in installed product and work order (look up to technician)

i have tried this 

helper class

public class WorkOrderHelper {

     public static void populateWorkOrderFields(list<SVMXC__Service_Order__c> WorkOrders){

         Set<Id> installedProductIds =new Set<Id>();
         Set<Id> locationIds =new Set<Id>();
         Set<Id> technicianIds =new Set<Id>();
         
         
        // retriving Installed product ids from work order
        for(SVMXC__Service_Order__c wo : WorkOrders) {
            installedProductIds.add(wo.SVMXC__Component__c);
            locationIds.add(wo.SVMXC__Site__c);
            technicianIds.add(wo.SVMXC__Preferred_Technician__c);
        }
        
        // getting all installed product with all required info 
        List<SVMXC__Installed_Product__c> listOfIP = [select id, SVMXC__Preferred_Technician__c
                                                         from  SVMXC__Installed_Product__c where ID in :installedProductIds];
        Map<Id,SVMXC__Installed_Product__c> mapProducts = new Map<Id,SVMXC__Installed_Product__c>();
         for(SVMXC__Installed_Product__c IP : listOfIP){
             mapProducts.put(IP.id,IP);
         }
                                                        
          System.debug('inside for loop');
         List<SVMXC__Site__c> listOFloc = [select id, location_technician1__c
                                                         from  SVMXC__Site__c where ID in :locationIds];

         Map<Id,SVMXC__Site__c> mapLocations = new Map<Id,SVMXC__Site__c>();
                 for(SVMXC__Site__c LOC : listOFloc){
             mapLocations.put(LOC.id,LOC);
         }                                        
         
         List<SVMXC__Service_Group_Members__c> listOfTechnicians = [select id, SVMXC__Service_Territory__c,SVMXC__Service_Group__c
                                                         from  SVMXC__Service_Group_Members__c where ID in :technicianIds];
         Map<Id,SVMXC__Service_Group_Members__c> mapTechnicians = new Map<Id,SVMXC__Service_Group_Members__c>();
                    
                 for(SVMXC__Service_Group_Members__c TECHNICIAN : listOfTechnicians){
             mapTechnicians.put(TECHNICIAN.id,TECHNICIAN);
         }                                                                        
        
         
        for(SVMXC__Service_Order__c wo : WorkOrders){
            
            SVMXC__Installed_Product__c prd = mapProducts.get(wo.SVMXC__Component__c);
            SVMXC__Site__c location = mapLocations.get(wo.SVMXC__Site__c);
            SVMXC__Service_Group_Members__c technician = mapTechnicians.get(wo.SVMXC__Preferred_Technician__c);
            System.debug('inside for loop');
            System.debug('product '+prd);
            System.debug('location '+location);
            System.debug('technician'+technician);
            if(prd != null && location != null && technician != null){
                System.debug('if cond 1');
                if(prd.SVMXC__Preferred_Technician__c == null){
                    System.debug('if cond 2');
                    if(wo.SVMXC__Primary_Territory__c == technician.SVMXC__Service_Territory__c){
                        System.debug('if cond 3');
                        wo.SVMXC__Service_Group__c = technician.SVMXC__Service_Group__c;
                        wo.SVMXC__Preferred_Technician__c = technician.Id;
                    }    
                }
                // compare primary territory with installed product Technician territory
            }
        }
     }
}

trigger

trigger PopulateTechnician on SVMXC__Service_Order__c (before insert,before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert || Trigger.isUpdate){
            WorkOrderHelper.populateWorkOrderFields(Trigger.New);
        }
    }
}
Installed products may hold preferred technician and if present will be
assigned to the work order.
● Location can hold preferred technicians under the Location Technicians. If
found, one technician will be picked and assigned.
● If installed product and locations both have preferred technicians,
Technicians from Installed products will be assigned.
● If installed products and locations have no preferred technicians, a check is
performed on the Primary Territory of Work order to get the technicians who
have the same territory mentioned in their Service Territory.
● ​​​​​​Service team to which technician belongs will also be assigned on the work order.
 
Controller

public class AccountAuraClr
 {
                @AuraEnabled
    public static List<Account> getAccountRecord()
   {
        return new List<Account>([Select id,Name,Phone,Type from Account where Type != null LIMIT  100]);
    }
}

Component

<aura:component controller="AccountAuraClr" implements="force:appHostable,forceCommunity:availableForAllPageTypes,
flexipage:availableForAllPageTypes" access="global">
 <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <!-- calling doInit method in Component Controller -->
    <aura:attribute name="accLst" type="Account[]"/> <!-- create Array type Account variable-->
    <article class="slds-card">
      <div class="slds-card__header slds-grid">
        <header class="slds-media slds-media_center slds-has-flexi-truncate">
          <div class="slds-media__figure">
            <span class="slds-icon_container slds-icon-standard-account" title="description of icon when needed">
                <lightning:icon iconName="standard:account" size="large" alternativeText="List account"/>
            </span>
          </div>
          <div class="slds-media__body">
            <h2 title="Survey">
           <!--   <a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="Account">
                <span class="slds-text-heading_small">Survey</span>
              </a>-->
            </h2>
          </div>
        </header>
       </div>
      <div class="slds-card__body">
        <table class="slds-table slds-table_bordered slds-no-row-hover slds-table_cell-buffer">
          <thead>
            <tr class="slds-text-title_caps">
              <th scope="col">
                <div class="slds-truncate" title="Name">Account Name</div>
              </th>
              <th scope="col">
                <div class="slds-truncate" title="Type">Total number of Contacts</div>
              </th>
                <th scope="col">
                <div class="slds-truncate" title="Type">Total number of Opportunity</div>
              </th>
              <th scope="col">
                <div class="slds-truncate" title="Phone">Delete</div>
              </th>
            </tr>
          </thead>
          <tbody>
              <aura:iteration items="{!v.accLst}" var="acc"> <!-- iteration account record.-->
                  <tr class="slds-hint-parent">
                      <th scope="row">
                          <div class="slds-truncate" title="Adam Choi"><a href="javascript:void(0);">{!acc.Name}</a></div>
                      </th>
                      <td>
                          <div class="slds-truncate" title="Company One">{!acc.Type}</div>
                      </td>
                      <td>
                          <div class="slds-truncate" title="Company One">{!acc.Type}</div>
                      </td>
                      <td>
                          <a onclick="{!c.RemoveRecord}" data-record="{!index}">
                                        <lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
                                        <span class="slds-assistive-text">Delete</span>
                                    </a>
                      </td>
                      
                  </tr>                     
              </aura:iteration>
          </tbody>
        </table>
      </div>
      <footer class="slds-card__footer"><a href="javascript:void(0);"><!--View All <span class="slds-assistive-text">entity type</span>--></a></footer>
    </article>
</aura:component>

js controller:-

({
                doInit : function(component, event, helper) {
                                helper.getAccontRecord(component); // Calling Helper method
                },
      RemoveRecord : function(component, event, helper) {
                                helper.removeRecord(component); // Calling Helper method
                }
})

js helper:-

({
                getAccontRecord : function( component ) {
                                var action = component.get("c.getAccountRecord"); //Calling Apex class controller 'getAccountRecord' method

        action.setCallback(this, function(response) {
            var state = response.getState(); //Checking response status
            var result = JSON.stringify(response.getReturnValue());
            if (component.isValid() && state === "SUCCESS")
                component.set("v.accLst", response.getReturnValue());  // Adding values in Aura attribute variable.   
        });
        $A.enqueueAction(action);
                },
    removeRecord: function(component, event, helper) {
        //Get the account list
        var accountList = component.get("v.getAccountRecord");
        //Get the target object
        var selectedItem = event.currentTarget;
        //Get the selected item index
        var index = selectedItem.dataset.record;
        //Remove single record from account list
        accLst.splice(index, 1);
        //Set modified account list
        component.set("v.accLst", accLst);
    }
})
I have 3 objects
Survey - parent object
Questions - child
Answers - child 
Relationship - lookup
I need to display survey name and total number of questions and total number of answers created under survey object.
I need to display in table

Example-. 
         Survey name.          Total Questions.     Total Answers.
1.      Email survey                 2.                              3.                     DeleteButton

DeleteButton is to delete that particular row
Please help me
Please anbody help me to write handler class??

trigger OppValidation on Opportunity (before insert,before update) {
    
    Id profileId= userinfo.getProfileId();
    String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
    if(Trigger.isupdate){
        for(Opportunity opp:Trigger.new){
            opportunity oldoppy= Trigger.oldmap.get(opp.id);
            
            if(opp.Active__c ==false && oldoppy.Active__c==True && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
        
    }
    
    if(Trigger.isinsert){
        for(Opportunity opp:Trigger.new){
            
            if(opp.Active__c ==false && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
    }
}
global class UpdateFunding implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
    }

    global void execute(Database.BatchableContext context, List<sObject> batch){
        Set<Id> Opportuniyids = new Set<Id>();

        for (sObject oppy : batch) {
            Opportuniyids.add(oppy.Id);
        }

        updatequote(Opportuniyids);
    }

    global void finish(Database.BatchableContext context) {}

    public void updatequote(set<id> oppyids){
        system.debug('opportuiy ids'+oppyids);
        List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
        for(Opportunity opp:opportunities) {
       Set<String> systems = new Set<String>();
        for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
        if (String.isNotBlank(oppObj.Funding__c)) {
            systems.addAll(oppObj.Funding__c.split(';'));
        }
    }
    String accountSystems = '';
    for (String value : systems) {
        accountSystems += value + ';';
    }
    accountSystems = accountSystems.removeEnd(';');
    try {
        update new Opportunity(Id = opp.id,Funding__c  = accountSystems);
    } catch (Exception e) {
        System.debug('Exception: ' + e.getMessage());
    }
        }       
    }

}

 

Need to create list view for Account object, i need to filter records based on "Account name" field.

The problem is
if 2 accounts has same name it will display all records that belong to 2 user.
How to avoid this?
it should display records belong to particular Account name.
and if 2 account names are same it should not display all records
 

Need to trigger with handler class.

I have a text field on Account that is "Primary contact"(text field)  where you will give the related contact name of that particular account, which ever contact name is given in that field shouldn't be able to delete by any user.
ex - if account A has 2 related contacts i.e, c1 and c2.
now i will update that Primary contact field with related contact c1.
now any user should not be able to delete that C1 related contact.
global class UpdateFunding implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
    }

    global void execute(Database.BatchableContext context, List<sObject> batch){
        Set<Id> Opportuniyids = new Set<Id>();

        for (sObject oppy : batch) {
            Opportuniyids.add(oppy.Id);
        }

        updatequote(Opportuniyids);
    }

    global void finish(Database.BatchableContext context) {}

    public void updatequote(set<id> oppyids){
        system.debug('opportuiy ids'+oppyids);
        List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
        for(Opportunity opp:opportunities) {
       Set<String> systems = new Set<String>();
        for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
        if (String.isNotBlank(oppObj.Funding__c)) {
            systems.addAll(oppObj.Funding__c.split(';'));
        }
    }
    String accountSystems = '';
    for (String value : systems) {
        accountSystems += value + ';';
    }
    accountSystems = accountSystems.removeEnd(';');
    try {
        update new Opportunity(Id = opp.id,Funding__c  = accountSystems);
    } catch (Exception e) {
        System.debug('Exception: ' + e.getMessage());
    }
        }       
    }

}
I have Created a field called Funding on Quote with values - Partial , Full and NA .
and i Created a field called Funding on Opportunity.
Write a batch class to rollup the unique funding field values from Quote to Opportunity if Opportunity stage is closed/won. Ex: if an opportunity has 6 quotes with funding Full, Full, NA, Partial ,NA, Partial then field on opportunity should be in format - Partial,Full,NA.
trigger OppValidation on Opportunity (before insert,before update) {
    
    Id profileId= userinfo.getProfileId();
    String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
    if(Trigger.isupdate){
        for(Opportunity opp:Trigger.new){
            opportunity oldoppy= Trigger.oldmap.get(opp.id);
            
            if(opp.Active__c ==false && oldoppy.Active__c==True && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
        
    }
    
    if(Trigger.isinsert){
        for(Opportunity opp:Trigger.new){
            
            if(opp.Active__c ==false && opp.stagename!='Closed Won' && profileName!='System Administrator'){
                opp.adderror('You do not have the access to perform this operation. Kindly contact your system administrator');
            }
        }
    }
}
I have Created a field on Account called Stage with values - In Progress, Closed. If the stage is changed to closed the trigger should auto update stage of all opportunities for that account to closed/won and close date to current day.
I created a checkbox field call active on opportunity . If a user other than system administrator tries to update the field to inactive when the stage field value is not closed/won show an error 'You do not have the access to perform this operation. Kindly contact your system administrator'
trigger NumberOfChild on Case (After Insert,After Update,After Delete) {
   List<Account> accList=new List<Account>();

    Set<Id> setAccIds = new Set<Id>();
    if(Trigger.isInsert){
         if(trigger.isAfter){
        for(Case con : Trigger.new){
            if(con.AccountId != null){
            setAccIds.add(con.AccountId);
                }
            }
        }
    } 
    system.debug('setAccIds ==> '+setAccIds);
    if(Trigger.isUpdate){
         if(trigger.isAfter){
        for(Case con : Trigger.new){ 
            if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId){
                   setAccIds.add(con.AccountId);
                setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
                }
          
            }        
        }
    }
    if(Trigger.isDelete){
        if(trigger.isAfter){
        for(Case con : Trigger.old) { 
            if(con.AccountId != null){
            setAccIds.add(con.AccountId);
                }
            }
        }
    }    
    for(Account acc :[Select id,Summary__c ,(Select id,Description from Cases) from Account where Id in : setAccIds]){
      String s ='';
        for(Case Con :acc.Cases){
            s+=Con.Description +',';
        }
        acc.Summary__c =  s.removeEnd(',');
        acclist.add(acc);
    }
    if(acclist.size()>0){
        update accList;     
    }
}
trigger sendMailToContactTrigger on Contact (after insert) {
    set<String> emailSet = new Set<String>();
    EmailTemplate temp=[Select id,Body from EmailTemplate where name='contact text email template'];
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    if(Trigger.IsAfter && Trigger.IsInsert){
        for(Contact Con : Trigger.new){
            if(Con.Email != Null){
                 Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
                singleMail.setHtmlBody(temp.Body);
                singleMail.setToAddresses(new List<String>{con.Email});
                singleMail.setTargetObjectId(con.Id);
                singleMail.setTemplateId(temp.Id);
                emails.add(singleMail);
            }
        }
    }
    if(emails.Size()>0){
    Messaging.sendEmail(emails);
    }
}