• Sainath Venkat
  • NEWBIE
  • 275 Points
  • Member since 2017

  • Chatter
    Feed
  • 5
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 69
    Questions
  • 140
    Replies
Hi,

I need help writing a test for the following trigger which submits a record for approval if the created_from_onboarding__c checkbox field is marked true.
trigger autoapprovenewhire on Change_of_statusnew__c (after insert) {
    for(Change_of_statusnew__c changeofstatus : trigger.new){
        if(changeofstatus.created_from_onboarding__c == TRUE){
            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(changeofstatus.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());
        }
    }
}
@AuraEnabled
    public static void updatePicturePath(String recId){
        //In Lightning Experience, Attachments are stored in ContentDocuments
        ContentDocumentLink docLink = [ SELECT ContentDocumentId
                               FROM ContentDocumentLink
                               WHERE LinkedEntityId = :recId order by Id desc Limit 1];
        //ContentVersion Id uniquely identifies the attachment
        ContentVersion ver = [SELECT Id FROM ContentVersion Where ContentDocumentId = :docLink.ContentDocumentId];
        //Update the Picture_Path field with the url of the image
        Speaker__c speaker = [SELECT Id FROM Speaker__c WHERE Id = :recId];
        speaker.Picture_Path__c = '/sfc/servlet.shepherd/version/download/'+ ver.Id;
        upsert speaker;
    }
====================================
Unexpected token 'void'.
A developer creates a Workflow Rule declaratively that updates a field on an object. An Apex update trigger exists for that object.
What happens when a user updates a record?  

A. No changes are made to the data.
B. Both the Apex Trigger and Workflow Rule are fired only once.
C. The Workflow Rule is fired more than once.
D. The Apex Trigger is fired more than once
I have the code which is trying to update records but I am getting error that duplicate Id in list, below is my class
I am getting error at update clonedPeriods
 
List<Rent_Schedule_Period__c> periods = [
        SELECT Id, Rent_Schedule__c
        FROM Rent_Schedule_Period__c
        WHERE Rent_Schedule__c IN :scheduleIds
    ];
    if(periods.isEmpty()) {
        return;
    }
    Set<Id> periodIds = new Map<Id, Rent_Schedule_Period__c>(periods).keySet();
    Map<id,List<Rent_Schedule_Period__c>> clonedMap=new Map<id,List<Rent_Schedule_Period__c>>();
   // List<Id> periodIdList = new List<Id>(periodIds);
    List<Rent_Schedule_Period__c> clonedPeriods = new CloneService()
        .withSource(new List<Id>(periodIds))
        .deepClone();
   List<Rent_Schedule_Period__c> toUpdate=new List<Rent_Schedule_Period__c>();
    Set<Rent_Schedule_Period__c> setrecords=new Set<Rent_Schedule_Period__c>(clonedPeriods);
    List<Rent_Schedule_Period__c> uniqueRecords=new List<Rent_Schedule_Period__c>(setrecords);

   String periodId;
    if(rentScheduleId!=null){
     List<Rent_Schedule_Period__c> period=[select id,name from Rent_Schedule_Period__c where Rent_Schedule__c=:rentScheduleId];
        if( period.size()>0){
            for(Rent_Schedule_Period__c pro : period)
            periodId=pro.id;
        }
    }
    system.debug('clonedPeriods.size()=='+clonedPeriods.size());
    for (Integer i = 0; i < clonedPeriods.size(); i++) {
        Rent_Schedule_Period__c clonedPeriod = clonedPeriods.get(i);
        system.debug('periodId=='+periodId);
        system.debug('clonedPeriod=='+clonedPeriod);
        if(periodId!=null){
           clonedPeriod.id=periodId;
        }else{
           clonedPeriod.Rent_Schedule__c =clonedScheduleByOriginalId.get(clonedPeriod.Rent_Schedule__c);
        }
   toUpdate.add(clonedPeriod);
    }
    if(periodId!=null){
        system.debug('uniqueRecords==='+clonedPeriods);
        update clonedPeriods;
        //update RentScheduleService.getPriorPeriodUpdates(toUpdate);
    }else{
        insert clonedPeriods;
       // update RentScheduleService.getPriorPeriodUpdates(clonedPeriods);
    }
    update RentScheduleService.getPriorPeriodUpdates(clonedPeriods);

    RentScheduleService.evaluateAndSave(SObjectUtils.collectIds(clonedSchedules));
}

 
How to show loading icon on VF Page until success or failure message appears.

I have a button on child object which will update the child and parent record, button is using VF Page and apex class.
I want to show loading image until success or failure message appears, can anyone help me out on this.

Apex class:
public class DeviationButton {
    public Lease_2__c a{get;set;}
    public String str;
    set<Id> opportunityId = new set<Id>();
    List<Lease_2__c> leaseupdate = new List<Lease_2__c>();
    List<Lease_2__c> leaselist = new List<Lease_2__c>();
    List<Opportunity> opptoUpdate = new List<Opportunity>();
    public DeviationButton(ApexPages.StandardController controller) {
        string currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        Lease_2__c allleases = [select Id, Opportunity__c,Deviation_Required__c,DeviationCount__c, Stage__c from Lease_2__c Where Id=: currentRecordId];
          //  allleases.Stage__c = 'Legal Review';
        if(  allleases.Stage__c == 'Deviation')
        {
              str = 'Deviation';
              allleases.Stage__c = 'Legal Review';
        }
            if(allleases.DeviationCount__c == 0 || allleases.DeviationCount__c == null){
                allleases.Deviation_Required__c = false;
            }
            else if(allleases.DeviationCount__c >= 1){
                allleases.Deviation_Required__c = true;
            }
        leaseupdate.add(allleases);
        Opportunity allopps = [select Id, StageName from Opportunity where Id =: allleases.Opportunity__c];
        allopps.StageName='Deal Approved';
        opptoUpdate.add(allopps);
    }
    
    public void MyActionMethod()
   {
        for(Lease_2__c l : leaseupdate)
        {
            if(str == 'Deviation' && l.stage__c =='Legal Review' )
            {
                leaseList.add(l);   
            }
            else{
                  ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You cannot Recall Deviation if Stage is not in Deviation'));
            }
        }
       if(leaseList.size()>0)
       {
           update leaseList;
           update opptoUpdate;
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Lease Record Has Been Successfully Recalled. Thank You!'));
       }
        //update leaseupdate;
        
    }

}
VF Page:
<apex:page standardController="Lease_2__c" extensions="DeviationButton" action="{!MyActionMethod}" lightningStylesheets="true" showQuickActionVfHeader="false"  > 
  
    <apex:pageMessages ></apex:pageMessages><h3 style="color:green">
             <!-- <b>Lease Has Been Successfully Recalled. Thank You!</b>-->
          </h3>
    
</apex:page>


 
Hello Everyone, I have two objects
  1. Time__c
  2. Resource__c
I have Stage__c field on two objects, time is parent and resource is child, now I wanto create a button on Resource__c object, on clicking the button, I want to update Stage__c on both objects to 'Recalled'.
Can anyone help me out to achieve this, I want to achieve with VF page and apex class here. I also want to show success message to user on updation of records.
How to create a VF page that will display child records on parent by grouping text field on child.

I have a text field status__c on child object, I want to group records based on that field.

for example,
Status__c = 1
record1
record2

Status__c = 2
record1
record2
record3

like this I want to show on VF page on parent record
Hello Everyone, I have two objects
1) Structure__c
2) Agent__c
here structure is the parent and agent is the child object, whenever structure is updating then I need to capture old field values and needs to create record in agent object which can be achieved with trigger.
but now the issue is we want to give field mapping option to end user which I think can be done with custom metadata

Can anyone explain or example code to do field mapping dynamically with custom metadata please.
Hello Everyone, I am working on getting the LWC superbadge but got struck at challenge 10, I am trying to complete the below challenge

"Integrate Third Party Scripts to build the component fiveStarRating"

but keep on getting the following error message.
"Challenge Not yet complete... here's what's wrong:
We can't find the API decorator being imported in fiveStarRating.js file. Make sure the component was created according to the requirements."

my Js is below, can anyone help me out in this issue here.
//import fivestar static resource, call it fivestar
import fivestar from '@salesforce/resourceUrl/fivestar';
import { reduceErrors } from 'c/ldsUtils';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { api, LightningElement } from 'lwc';
// add constants here
const TOAST_ERROR_TITLE = 'Error loading five-star';
const ERROR_VARIANT = 'error';
const READ_ONLY_CLASS = 'readonly c-rating';
const EDITABLE_CLASS = 'c-rating';
export default class FiveStarRating extends LightningElement {
  //initialize public readOnly and value properties
  @api readOnly = false;
  @api value;

  editedValue;
  isRendered;

  //getter function that returns the correct class depending on if it is readonly
  get starClass() {
    return this.readOnly ? READ_ONLY_CLASS : EDITABLE_CLASS;
  }

  // Render callback to load the script once the component renders.
  renderedCallback() {
    if (this.isRendered) {
      return;
    }
    this.loadScript();
    this.isRendered = true;
  }

  //Method to load the 3rd party script and initialize the rating.
  //call the initializeRating function after scripts are loaded
  //display a toast with error message if there is an error loading script
  loadScript() {
    Promise.all([
      loadScript(this, fivestar + '/rating.js'),
      loadStyle(this, fivestar + '/rating.css')
    ])
      .then(() => {
        this.initializeRating();
      })
      .catch(error => {
        this.dispatchEvent(new ShowToastEvent({
          title: TOAST_ERROR_TITLE,
          message: error,
          variant: ERROR_VARIANT
        }));
      })
  }

  initializeRating() {
    let domEl = this.template.querySelector('ul');
    let maxRating = 5;
    let self = this;
    let callback = function (rating) {
      self.editedValue = rating;
      self.ratingChanged(rating);
    };
    this.ratingObj = window.rating(
      domEl,
      this.value,
      maxRating,
      callback,
      this.readOnly
    );
  }

  // Method to fire event called ratingchange with the following parameter:
  // {detail: { rating: CURRENT_RATING }}); when the user selects a rating
  ratingChanged(rating) {
    this.dispatchEvent(new CustomEvent('ratingchange', { detail: { rating } }));
  }
}

 
I am pretty new to Salesforce apex development, so came accross one specific requirement where I need to create LWC component.
I have two objects
  1. Shadow_Note__c
  2. Case_History_Normalized__c
Based on picklist value I need to bind the data from above two objects and display it on LWC component, I tried below controller
 
@AuraEnabled(Cacheable=true)
public static Map<string,List<Shadow_Note__c>> populateTaggedNotesForCase(Id RecordId){
    //set<Id> caseRecordId = new set<Id>();
    String caseRecordId = '';
    List<Root_Cause_Analysis__c> rcaRecords = [Select Id, Case__c from Root_Cause_Analysis__c where Id =: RecordId order by CreatedDate desc];
    /*for(Root_Cause_Analysis__c rca: rcaRecords){
        caseRecordId.add(rca.Case__c);
    }*/
    if(rcaRecords.size() > 0)
        caseRecordId = rcaRecords[0].Case__c;
    Map<string,List<Shadow_Note__c>> res = new Map<string,List<Shadow_Note__c>>();
    Schema.DescribeFieldResult fieldResult = Shadow_Note__c.Note_Tag__c.getDescribe();
    List<Schema.PicklistEntry> ple =fieldResult.getPicklistValues();
    for (Schema.PicklistEntry a:ple ){
            res.put(a.value , new List<Shadow_Note__c>());
    }
    List<LTNG_HTERCA_RightTagWrapper> shadowNotesTagList = new List<LTNG_HTERCA_RightTagWrapper>();
    List<Shadow_Note__c> allshadownotes = [SELECT Note__c,Note_Tag__c,Date_Time_Created_in_CSOne__c,CreatedBy_Name__c From Shadow_Note__c 
    WHERE Case__c =: caseRecordId AND Note_Tag__c != null 
    ORDER BY CreatedDate ASC];
    List<Case_History_Normalized__c> allnormalisedNotes = [SELECT Tags__c,IsTagged__c From Case_History_Normalized__c 
                                  WHERE Case__c =: caseRecordId AND IsTagged__c = TRUE ORDER BY CreatedDate ASC LIMIT 10];
    for(Shadow_Note__c sn: allshadownotes){
        List<String> noteTags = sn.Note_Tag__c.split(';');
        for(String tag: noteTags){
            if(res.containsKey(tag)){
                List<Shadow_Note__c> notesList = res.get(tag);
                notesList.add(sn);
                res.put(tag, notesList);
                system.debug('res is ++: ' + res);
                 
            }
        }
    }
    System.debug('the result is:' + JSON.serializePretty(res));
    return res;
}

the above controller is working for to display one object data i.e Shadow_Note__c but can anyone guide how to achieve for Case_History_Normalized__c object data, maybe a wrapper will work but can anyone guide me how to create a wrapper here to hold the fields data please
I am working on one of the lightning web component which will show child records based on picklist value, On parent detail page, I will have component which will fetch and display the child records but I want to show them based on picklist field, I want to group records and show them based on picklist value, on child object I have picklist field for which I need to group records based on that value
Picklistvalue1
ChildRecord1
ChildRecord2

Picklistvalue2
ChildRecord100
ChildRecord101

Picklistvalue3
ChildRecord200
ChildRecord201
I tried below apex class but just want to know whether I am on right track and also how to create LWC Component
 
public class RightTagWrapper {
@AuraEnabled
public String TagTypeName;
@AuraEnabled
public List<Shadow_Note__c> shadownotes;

public RightTagWrapper(String TagTypeName, List<Shadow_Note__c> shadownotes) {
   this.TagTypeName = TagTypeName;
   this.shadownotes = shadownotes;
}
  @AuraEnabled(Cacheable=true)
  public static List<RightTagWrapper> caseTrxMap(Id RecordId){
string caseRecordId;
        List<Root_Cause_Analysis__c> RCARecord= [select Id,Case__c from Root_Cause_Analysis__c where Id=:RecordId];
        for(Root_Cause_Analysis__c rca: RCARecord){
            caseRecordId = rca.Case__c;
        }

List<RightTagWrapper> shadowNotesTagList = new List<RightTagWrapper>();
Map<string,string> TagPickvals = new Map<string,string>();
             Schema.DescribeFieldResult fieldResult = Shadow_Note__c.Note_Tag__c.getDescribe();
             List<Schema.PicklistEntry> ple =fieldResult.getPicklistValues();
             for (Schema.PicklistEntry a:ple ){
             TagPickvals.put(a.value,a.Label);
             }

List<Shadow_Note__c> allshadownotes = [SELECT Note__c,Note_Tag__c From Shadow_Note__c 
                               WHERE Case__c =: caseRecordId AND Note_Tag__c != null ORDER BY CreatedDate ASC LIMIT 10];
List<Shadow_Note__c> shadownotestagType;
for (string str: TagPickvals.Keyset()) {

    shadownotestagType = new List<Shadow_Note__c>();

    for (Shadow_Note__c sn : allshadownotes) {
        if (TagPickvals.containsKey(sn.Note_Tag__c)) {
              shadownotestagType.add(sn);
        }                 
    }

    shadowNotesTagList.add(
        new RightTagWrapper(
           TagPickvals.get(str),
           shadownotestagType
       )
   );

}
return shadowNotesTagList;
  }
  }

 
Can anyone help me out in creating a LWC component where I want to show group of case records based on Status Picklist.

On datatable, I want to show Cases which are active and inactive, under active I want to show all cases which are active and under inactive I want to show all cases which are inactive.

for example

ACTIVE
CASE1
CASE2
CASE3

Inactive
Case100
Case101
Case103

Active and Inactive are picklist values on case object under Status__c field
Can anyone helpme out how to create a lightning web component to ftech child details on parent record detail page.

For example, On Account detail page, I want show related contact and cases
Can anyone help me out inwriting wrapper class to fetch fields from different objects to show it on Lighning web component.

For an account I want to fetch fields from Contact, Case,Opportunity objects so that thosevales will be shown on LWC.

Can anyone help me out in this.
I have a look up field and picklist fields on VF Page,
Look up field is having lookup to Project object, if users selects a Project in lookup field and if Project__c.Account = 'Test' then I want picklist value to be 'No' and disable it.
Can anyone help me out in achieving this on VF Page
I am working on one trigger which will populate the Project id in Project Roles.

I have SOW__c object which is having self lookup relationship, Project__c object is having look up to sow object and Project_Role__c object is having look up to sow.

since SOW is having self look up, I will be having parent sow and child sow records, if I create any role to child sow then I want to populate project id that is related to parent sow to the role that is creating to child sow, I tried below a class but somehow it's not working.

Can anyone help me out with this issue, please?
 
public static void CRroleProjectUpdate(List<Project_Role__c> projectroles){
    set<Id> CRsowId = new set<Id>();
    Map<Id,List<Project__c>> CRProjectMap = new Map<Id,List<Project__c>>();
    for(Project_Role__c proles : projectroles){
        CRsowId.add(proles.SOW__r.Related_SOW__c);
        system.debug('CRsowId is ' + CRsowId);
    }
    if(!CRsowId.isEmpty()){
        for(Project__c project:[select Id, SOW__c from Project__c where SOW__c IN: CRsowId]){
            list<Project__c> CRProjectList= CRProjectMap.containsKey(project.Sow__c)?CRProjectMap.get(project.Sow__c):new list<Project__c>();
            CRProjectList.add(Project);
            CRProjectMap.put(project.SOW__c, CRProjectList);
        }
        for(Project_Role__c proles : projectroles){
            if(CRProjectMap.ContainsKey(proles.SOW__r.Related_SOW__c)){
                for(Project__c p : CRProjectMap.get(proles.SOW__r.Related_SOW__c)){
                    proles.Project__c = p.Id;
                }
            }
        }
    }
}

 
Can anyone helpme out in scheduling a batch apex which need torun at 12:10 AM Everyday.

My batch apex code:
global class BatchImpliedConsentLead implements Database.Batchable<sObject> {
    global integer recordsProcessed = 0;
    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator('SELECT Id, Implied_Consent__c,Implied_Consent_Date__c,HasOptedOutOfEmail,CASL_Opt_In__c,CASL_Opt_In_Status__c, Implied_Consent_Expiry__c from Lead WHERE Implied_Consent__c != null AND Implied_Consent_Expiry__c != null');
    }
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        for(lead l: scope){
            //date d = l.Implied_Consent_Expiry__c.date();
            if((l.Implied_Consent__c == true) && (l.Implied_Consent_Expiry__c.date() <= system.today()) ){
                l.Implied_Consent_Date__c = null;
                l.Implied_Consent__c = false;
                l.HasOptedOutOfEmail = true;
                l.CASL_Opt_In__c = false;
                l.CASL_Opt_In_Status__c = 'Removed';
                
            }
            update scope;
        }
    }
        global void finish(Database.BatchableContext bc){
            system.debug(recordsProcessed +'records Processed');
            AsyncApexJob job = [select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems,CreatedBy.Email from AsyncApexJob where Id =: bc.getJobId()];
    }

}

 
I created one trigger on User object which will update the last login to account if account name matches with user.Name field.

but somehow my trigger is not at all updating the lastlogin field on account object even though name matches, can anyone helps me out in this issue here.

My trigger code is below
 
trigger USERLOGIN on User (after insert, after Update) {
    map<string, User> ObjMap = new map<string, User>();
    
    for(User obj: Trigger.new)
    {
        if (obj.Name != Null)
        {
            ObjMap.put(obj.Name, obj);
        }
    }
    system.debug('UserMap :' + ObjMap);
    List<Account> accounts = [SELECT Id, logindate__c,Name FROM Account WHERE Name IN :ObjMap.KeySet()];
    List<Account> accUpdateList = new List<Account>();
    system.debug('Account :' + accounts);
    
    for(Account c: accounts)
    {
        User obj = ObjMap.get(c.Name);
        c.logindate__c = obj.LastLoginDate;
        c.usertextemail__c = obj.Email;
        accUpdateList.add(c);
    }
    
    if(accUpdateList.size() > 0)
    {
        update accUpdateList;
    }
}

 
I need help in writing a trigger, I have two objects

1) Opportunity
2) Opportunity_ Program__c

both are having lookup relationship, Opportunity is Parent and Opportunity Program is child.

Opportunity program has Status field.

I need to write a trigger on Opportunity Program object, for a given Opportunity if any of the child records contains status as "MATR" then Opportunity.StageName = 'Closed Won', if any of the child record for a given opportunity does not contain "MATR" then Opportunity.StageName = 'Closed Lost'

Can anyone helps me out in this issue please.
I am working one trigger which will update the stage in Opportunity based on child field.
for a given opportunity, if any of the child record contains Program_Action__c = "MATR" then I want to update the status to Closed Won, if none of the child records contains MATR and only contains "WADM" or "WAPP" then stage is Closed Lost and child records contains Program_Action__c = "ADMT" then stage should be Open
My code is working for all conditions but if any of the child record contains MATR then stage is not updating to "Closed Won".
Can anyone helps me out in this issue here.
public class ParentUpdateFromChildOpportunity {
public static void ParentUpdate(List<Opportunity_Programs__c> oppProgramList){
    try{
            System.debug('Opportunity List==>'+oppProgramList);

    Set<Id> opportunityId = new Set<Id>();
    for(Opportunity_Programs__c oppPrgmObj : oppProgramList){
        opportunityId.add(oppPrgmObj.Opportunity_ID__c);
    }
    List<Opportunity> opportunityList = New List<Opportunity>();
    opportunityList = [Select Id,
                       StageName
                       From Opportunity
                       Where Id IN : opportunityId
                       Limit 50000
                      ];
    Integer won=1;
    List<Opportunity> olist=new List<Opportunity>();
    for(Opportunity_Programs__c oppPrgmObj2 : oppProgramList){
        for(Opportunity oppObj : opportunityList){
            if(oppPrgmObj2.Program_Action__c == 'MATR' && (oppPrgmObj2.Opportunity_ID__c == oppObj.Id)){
                oppObj.StageName='Closed Won';
                olist.add(oppObj);
                won=2;
            }
            else if((oppPrgmObj2.Program_Action__c == 'WADM' ||oppPrgmObj2.Program_Action__c == 'WAPP') && (oppPrgmObj2.Opportunity_ID__c == oppObj.Id)){
                    oppObj.StageName='Closed Lost';
                    olist.add(oppObj);
                    won=2;
                }

            else if((oppPrgmObj2.Program_Action__c == 'ADMT' && (oppPrgmObj2.Opportunity_ID__c == oppObj.Id)){
                oppObj.StageName='Open';
                olist.add(oppObj);
                    won=2;
            }
        }
    }
    if(won == 2){
        system.debug('enter won');
        Update olist;
    }
    }catch(Exception e){
        system.debug('message::'+e.getMessage()+'line::'+e.getLineNumber());
    }
}
 }

 
I need help in writing a trigger here. I have two objects

1) Opportunity
2) Opportunity_Programs__c

I have lookup relationship between them, opportunity is parent and Opportunity_Programs__c is child, so one opportunity can have multiple Opportunity_Programs__c.

I have Status__c field in Opportunity_Programs__c object, so if Opportunity_Programs__c records that related to particular opportunity has Status__c value as "Open" then I need to update Opportunity stage to Open, if Stage__c is "Close" then I need to update Opportuntiy stage to "Closed Lost"

Can anyone help me out in this issue here
Can anyone help me out in writing batch apex that will create or update records.I never worked on batch apex so struggling here I have two objects
1) SIS_Staging__c
2) Contact
Both objects are having same field Siscode__c, so on inserting records in SIS_Staging__c, I need to check if any contact records are having same Siscode__c or not, if yes then I need to update else I need to create Contact.
I tried below code but when I run batch apex in anonymous window then I am getting below error.
"Constructor not defined: [BatchSISstagingObject].()"
My code is below.
 
global class BatchSISstagingObject implements Database.Batchable<sObject>{
    List <SIS_Staging__c> mapSisobject = new List <SIS_Staging__c> ();
    List <Contact> contactlist1 = new List <Contact> ();
    
    global BatchSISstagingObject(List <SIS_Staging__c> sisobjectUpdate) {
        mapSisobject=sisobjectUpdate;
        
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return DataBase.getQueryLocator([SELECT Id, SIS_Student_ID__c
                                         FROM Contact
                                        ]);
    }
    global void execute(Database.BatchableContext BC , List <Contact> contactlist) {
        for (SIS_Staging__c acct : mapSisobject){ 
            for (Contact con : contactList){
                if (con.SIS_Student_ID__c == acct.Name){
                        contactlist1.add(new Contact(
                            Id = con.Id,
                            FirstName = acct.First_Name__c,
                            LastName = acct.Last_Name__c
                           ));
                    }
            }   
        }
        
         update contactlist1;
    } 
    global void finish(Database.BatchableContext BC){
        
    }

}

 
Can anyone help me out in writing batch apex that will create or update records. I have two objects
1) Staging_Event__c
2) Contact
Both objects are having same field Siscode__c, so on inserting records in Staging_Event__c, I need to check if any contact records are having same Siscode__c or not, if yes then I need to update else I need to create Contact.

Can anyone help me out on writing batch apex here if possible.
Can anyone help me out inwriting wrapper class to fetch fields from different objects to show it on Lighning web component.

For an account I want to fetch fields from Contact, Case,Opportunity objects so that thosevales will be shown on LWC.

Can anyone help me out in this.
I need help in writing a trigger, I have two objects

1) Opportunity
2) Opportunity_ Program__c

both are having lookup relationship, Opportunity is Parent and Opportunity Program is child.

Opportunity program has Status field.

I need to write a trigger on Opportunity Program object, for a given Opportunity if any of the child records contains status as "MATR" then Opportunity.StageName = 'Closed Won', if any of the child record for a given opportunity does not contain "MATR" then Opportunity.StageName = 'Closed Lost'

Can anyone helps me out in this issue please.
Hello Everyone, I have two objects
  1. Time__c
  2. Resource__c
I have Stage__c field on two objects, time is parent and resource is child, now I wanto create a button on Resource__c object, on clicking the button, I want to update Stage__c on both objects to 'Recalled'.
Can anyone help me out to achieve this, I want to achieve with VF page and apex class here. I also want to show success message to user on updation of records.
How to create a VF page that will display child records on parent by grouping text field on child.

I have a text field status__c on child object, I want to group records based on that field.

for example,
Status__c = 1
record1
record2

Status__c = 2
record1
record2
record3

like this I want to show on VF page on parent record
Hi, 

When I create the Opportunity with the Probability=20, then the opportunity owner will be automatically added to Account Team of the associated account for that Opportunity. My tigger is as follows:- 

trigger opportunityAcountTeam on Opportunity (after insert, after update) {
    LIST<Opportunity> listOpp = new LIST<Opportunity>();
    SET<ID> oppIds = new SET<ID>();
    LIST<AccountTeamMember> listAccTeamMember = new LIST<AccountTeamMember>();
    //LIST<AccountShare> listShare = new LIST<AccountShare>();
    if(Trigger.IsAfter && Trigger.IsInsert) {
        for(Opportunity newOpp : Trigger.new) {
            if(newOpp.Probability == 20) {  
                listOpp.add(newOpp);
                oppIds.add(newOpp.AccountId);
                    AccountTeamMember newAccMember = new AccountTeamMember();
                    newAccMember.AccountAccessLevel = 'Edit';
                    newAccMember.OpportunityAccessLevel = 'Read';
                    newAccMember.TeamMemberRole = 'Account Manager';
                    newAccMember.AccountId = newOpp.AccountId;
                    newAccMember.UserId = newOpp.OwnerId;
                    //AccountShare newAccShare = new AccountShare();
                    //newAccShare.AccountAccessLevel='Read';
                     //newAccShare.OpportunityAccessLevel = 'Read Only';
                     //newAccShare.CaseAccessLevel='Read Only';
                    //newAccShare.AccountId = newOpp.AccountId;
                    //newAccShare.UserOrGroupId = newOpp.OwnerId;                    
                    listAccTeamMember.add(newAccMember);
                    //listShare.add(newAccShare);
        
                        if(listAccTeamMember != NULL) {
                        insert listAccTeammember;                        
                        }
           }
        }       
    }
}

I am getting following error:-

opportunityAcountTeam: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account]: [Account]: Trigger.opportunityAcountTeam: line 27, column 1

Kindly advise as I am not able to solve the problem.

Thanks
Vijay Zutshi
Can anyone help me out in creating a LWC component where I want to show group of case records based on Status Picklist.

On datatable, I want to show Cases which are active and inactive, under active I want to show all cases which are active and under inactive I want to show all cases which are inactive.

for example

ACTIVE
CASE1
CASE2
CASE3

Inactive
Case100
Case101
Case103

Active and Inactive are picklist values on case object under Status__c field
Can anyone helpme out how to create a lightning web component to ftech child details on parent record detail page.

For example, On Account detail page, I want show related contact and cases
I created one trigger on User object which will update the last login to account if account name matches with user.Name field.

but somehow my trigger is not at all updating the lastlogin field on account object even though name matches, can anyone helps me out in this issue here.

My trigger code is below
 
trigger USERLOGIN on User (after insert, after Update) {
    map<string, User> ObjMap = new map<string, User>();
    
    for(User obj: Trigger.new)
    {
        if (obj.Name != Null)
        {
            ObjMap.put(obj.Name, obj);
        }
    }
    system.debug('UserMap :' + ObjMap);
    List<Account> accounts = [SELECT Id, logindate__c,Name FROM Account WHERE Name IN :ObjMap.KeySet()];
    List<Account> accUpdateList = new List<Account>();
    system.debug('Account :' + accounts);
    
    for(Account c: accounts)
    {
        User obj = ObjMap.get(c.Name);
        c.logindate__c = obj.LastLoginDate;
        c.usertextemail__c = obj.Email;
        accUpdateList.add(c);
    }
    
    if(accUpdateList.size() > 0)
    {
        update accUpdateList;
    }
}

 
I need help in writing a trigger, I have two objects

1) Opportunity
2) Opportunity_ Program__c

both are having lookup relationship, Opportunity is Parent and Opportunity Program is child.

Opportunity program has Status field.

I need to write a trigger on Opportunity Program object, for a given Opportunity if any of the child records contains status as "MATR" then Opportunity.StageName = 'Closed Won', if any of the child record for a given opportunity does not contain "MATR" then Opportunity.StageName = 'Closed Lost'

Can anyone helps me out in this issue please.
Hello Guys

i am new to the trigges and apex development, so here  is my requirement - There is checkbox Called "Private__c" in account object
Once locked, if a new Lead is created with this Private Locked Account which already has a Allocated Owner, then a new Contact should be created for this Account under the allocated Account owner name. Lead will not be created. 

And If a new lead is added without a Private Account checkbox being checked then allow the Lead to be created with Lead creator as the Lead owner. 

so far i have tried to design a trigger, but its not meeting up my goal
 
trigger AutoConvertLeadAccount on Lead (after insert) {
    Set<String> leademails = new Set<String>();
    List<Lead> newLeads = new List<Lead>();

    // Get all the new leads
    for(Lead l : system.trigger.new){
        newLeads.add(l);
        leademails.add(l.email);
    }

    /* Make some maps of account and email addresses */
    List<Account> AccountList = [select Id, Website, OwnerId from Account where Website IN: leademails];
    Map<ID, String> peAccounts = new Map<ID, String>();
    Map<ID, ID> peAccountsOwner = new Map<ID, ID>();

if(AccountList.size()>0){
    // Generic map for preventing loss of ids
    for(Account a : AccountList){
        peAccounts.put(a.id, a.Website);
        peAccountsOwner.put(a.id, a.OwnerId);
    }

    // We will need this to get the id from the email address
    Map<String, ID> peAccountsFlipped = new Map<String, ID>();
    for(ID i : peAccounts.keyset()){
        peAccountsFlipped.put(peAccounts.get(i), i);
    }

    /* System Conversion Requirements */
    leadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
    Database.LeadConvert lc = new Database.LeadConvert();

    /* Configuring Payload */    
    for (Lead nl : newleads) {
        lc = new Database.LeadConvert();
        lc.setLeadId(nl.id);
        lc.setOverwriteLeadSource(false);
        lc.setConvertedStatus(convertStatus.MasterLabel);

        // Check to see if account already exists
        if(!peAccounts.isEmpty()){
            if(peAccountsFlipped.get(nl.email)!=null){
                lc.setAccountId(peAccountsFlipped.get(nl.email));
                lc.setOwnerId(peAccountsOwner.get(peAccountsFlipped.get(nl.email)));
                lc.setDoNotCreateOpportunity(true);
            }    
        } else {
            // In the event an account doesn't exist
            lc.setOwnerId(nl.OwnerId);
            lc.setDoNotCreateOpportunity(false);
            lc.setOpportunityName(nl.Name);
        }
        leadConverts.add(lc);
    }

    // Fire Payload
    Database.LeadConvertResult[] lcr = Database.convertLead(leadConverts);
    System.debug(LoggingLevel.INFO, lcr);
 }
}

 
I need help in writing a trigger here. I have two objects

1) Opportunity
2) Opportunity_Programs__c

I have lookup relationship between them, opportunity is parent and Opportunity_Programs__c is child, so one opportunity can have multiple Opportunity_Programs__c.

I have Status__c field in Opportunity_Programs__c object, so if Opportunity_Programs__c records that related to particular opportunity has Status__c value as "Open" then I need to update Opportunity stage to Open, if Stage__c is "Close" then I need to update Opportuntiy stage to "Closed Lost"

Can anyone help me out in this issue here
Can anyone help me out in writing batch apex that will create or update records.I never worked on batch apex so struggling here I have two objects
1) SIS_Staging__c
2) Contact
Both objects are having same field Siscode__c, so on inserting records in SIS_Staging__c, I need to check if any contact records are having same Siscode__c or not, if yes then I need to update else I need to create Contact.
I tried below code but when I run batch apex in anonymous window then I am getting below error.
"Constructor not defined: [BatchSISstagingObject].()"
My code is below.
 
global class BatchSISstagingObject implements Database.Batchable<sObject>{
    List <SIS_Staging__c> mapSisobject = new List <SIS_Staging__c> ();
    List <Contact> contactlist1 = new List <Contact> ();
    
    global BatchSISstagingObject(List <SIS_Staging__c> sisobjectUpdate) {
        mapSisobject=sisobjectUpdate;
        
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return DataBase.getQueryLocator([SELECT Id, SIS_Student_ID__c
                                         FROM Contact
                                        ]);
    }
    global void execute(Database.BatchableContext BC , List <Contact> contactlist) {
        for (SIS_Staging__c acct : mapSisobject){ 
            for (Contact con : contactList){
                if (con.SIS_Student_ID__c == acct.Name){
                        contactlist1.add(new Contact(
                            Id = con.Id,
                            FirstName = acct.First_Name__c,
                            LastName = acct.Last_Name__c
                           ));
                    }
            }   
        }
        
         update contactlist1;
    } 
    global void finish(Database.BatchableContext BC){
        
    }

}