• ankit bansal
  • NEWBIE
  • 150 Points
  • Member since 2014

  • Chatter
    Feed
  • 4
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 43
    Replies

Hello,
I'm receiveing relationship error while querying for Cases Ids and their attached document Ids:

Select id, (SELECT Id FROM ContentDocumentLink) From Case limit 5

Can you please support me to run the above query in one statement?
Thank you
Yaman

Good day. In my first tab the if statement is not running while in the second tab the if statement runs well.
 
FIRST TAB  
Trigger CaseUpdate on Case(Before Insert, Before Update, Before Delete, After Insert,
                             After Update, After Delete, After Undelete){
    if(Trigger.isAfter){
        if(Trigger.isUpdate){
            Set<Id> newIds = new Set<Id>();
            Set<Id> oldIds = new Set<Id>();
            for(Case newLooper : Trigger.new){
                newIds.add(newLooper.AccountId);
            }
            for(Case oldLooper : Trigger.old){
                oldIds.add(oldLooper.AccountId);
            }
            List<Case> newList = new List<Case>([Select Id, CaseNumber, Status from Case where AccountId=:newIds]);
            List<Case> oldList = new List<Case>([Select Id, Status from Case where AccountId=:oldIds]);
            List<Account> accList = new List<Account>([Select Id, Last_Updated_Cases__c from Account where Id=:newIds]);
            Case newCase = new Case();
            Case oldCase = new Case();
            Account accountObject = new Account();
            for(Case oldCaseLooper : oldList){
                oldCase = oldCaseLooper;
            }
                //System.debug('ID 1: ' + oldCase.Id);
            for(Account accountLooper : accList){
                accountObject = accountLooper;
            }
                //System.debug('ID 2: ' + accountObject.Id);
            for(Case newCaseLooper : newList){
                newCase = newCaseLooper;
                if(oldCase.Id == newCase.Id &&
                 oldCase.Status != newCase.Status){
                    accountObject.Last_Updated_Cases__c = newCase.CaseNumber;
                    update accountObject;
                }
            }
        }
    }                                
}
 
 
SECOND TAB
Trigger CaseUpdate on Case(Before Insert, Before Update, Before Delete, After Insert,
                             After Update, After Delete, After Undelete){
    if(Trigger.isAfter){
        if(Trigger.isUpdate){
            Set<Id> caseId = new Set<Id>();    
       
        for(Case caseIdLooper : Trigger.new){
            caseId.add(caseIdLooper.AccountId);
        }      
     
        //Calling the Account Obj to get the Last updated cases field
        List<Account> accountObject = new List<Account>([Select Id, Last_Updated_Cases__c from Account
                                                       where Id=:caseId]);
       
        Case oldListOfcase = new Case();
        Case newListOfCase = new Case();
        Account accObject = new Account();
       
        for(Account accLooper : accountObject){
            accObject = accLooper;
        }
       
        for(Case oldCaseLooper : Trigger.old){
            oldListOfCase = oldCaseLooper;
        }
        System.debug('ID: ' + oldListOfCase.Id);
        for(Case newCaseLooper : Trigger.new){
            newListOfCase = newCaseLooper;
            if(oldListOfCase.Id == newListOfCase.Id &&
               oldListOfCase.Status != newListOfCase.Status){
               accObject.Last_Updated_Cases__c = newListOfCase.CaseNumber;
                   update accObject;
            }
        }
    }
  }                                
}
  • October 18, 2021
  • Like
  • 0
Hi,

We have a very simpel standard object.
  • An autonumber for the name
  • A textfield for a unique string (length 18)
  • A phone number field
  • A date field

Plus ofcourse the standard created by etc...
No track activities or track field history, only reports and search and the sharing and API access enabled

Now we are populating this object with data from an outside source, we want to import about 1,5 milion records. This is about 60MB of data on our external database. 
But when imported only a third we were already at 1Gig of storage space in Salesforce, that would mean that all 1,5 million lines would be arround 3Gig of data. I understand that some meta data is stored, but going from 60MB to 3Gig to store a few fields of data?

Are we doing something wrong? Why is SF using this amount of storage for this simple request?

I upserted 150 records wiith salesforce data loader. The batch size was set as 200.A single record in that 150 records failed to upload but the error was shown for all the 150 and none of the record was upserted,but in a seperate incident the data loader upserted 149 records and showed error for only that one record. What is this behaviour of data loader and how can it be changed ?
I upserted 150 records wiith salesforce data loader. The batch size was set as 200.A single record in that 150 records failed to upload but the error was shown for all the 150 and none of the record was upserted,but in a seperate incident the data loader upserted 149 records and showed error for only that one record. What is this behaviour of data loader and how can it be changed ?
I'm trying to create a lightning web component that allows you to create a new record for a custom object. I know the values are being processed correctly, but when I try to create the record, I get a toast error telling me I don't have access to the record. I haven't implemented any security on my objects, and am logged in as the system administrator. If I navigate to the object and create a new one there, I have no issues.

My code is this: 

import { LightningElement, wire, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { createRecord } from 'lightning/uiRecordApi';
import ORDER_OBJECT from '@salesforce/schema/Customer_Order__c';
import CID_FIELD from '@salesforce/schema/Customer__c.Name';
import ORDER_DATE_FIELD from '@salesforce/schema/Customer_Order__c.Order_Date__c';
import getCustomerCID from '@salesforce/apex/GetComponents.getCustomerCID';
export default class CreateNewOrder extends LightningElement {
   
    Title = 'Create A New Order';
    //@api ORDER_OBJECT;
    //@api CID_FIELD;
    //@api ORDER_DATE_FIELD;
    objectApiName = ORDER_OBJECT;
    cid;
    date;
   
    //wires a list of customer objects containing the Name field into cidList
    @wire(getCustomerCID)
    cidList;
    //iterate through cidList and push each element to the listOptions array, which is returned as the combobox options
    get cidOptions() {
        var listOptions = [];
        if(this.cidList.data){
            this.cidList.data.forEach(ele =>{
                listOptions.push({label:ele.Name , value:ele.Name});
            });
        }
        return listOptions;
    }
    //pass combobox selection to cid
    handleCIDChange(event){
        this.cid = event.detail.value;
    }
    //pass date selection to date
    handleDateChange(event){
        this.date = event.detail.value;
    }
   
    //create record
    handleCreateOrder(event){
        var fields = {CID_FIELD: this.cid, ORDER_DATE_FIELD: this.date};
       
        const recordInput = {apiName: 'ORDER_OBJECT', fields};
        createRecord(recordInput)
        .then(account => {
            this.accountId = account.id;
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: "Ordered placed by Customer " + this.cid + " on " + this.date + ".",
                    variant: 'success',
                }),
            );
        })
        .catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: error.body.message,
                    variant: 'error',
                }),
            );
        });
        //test to see if values are correct
        const toastEvent = new ShowToastEvent({
            title: "TEST TOAST",
            message: "RECORD VALUES TO ADD: CUSTOMER_C.NAME " + this.cid + " AND CUSTOMER_ORDER_C.ORDER_DATE " + this.date + ".",
            variant: "success"
        });
        this.dispatchEvent(toastEvent);
    }
}
can we run the the query lifetime in salesforce ????

tell me..
Public class ProspectContactCntrl
{
    Public List<SelectOption> recTypeLst {set;get;}
    Public List<RecordType> recLst {set;get;}
    public string selRecordType {set;get;}
    public String contactId {set;get;}
    public String leadId {set;get;}
    public String contactName {set;get;}
   public ProspectContactCntrl(ApexPages.StandardController stdController) { 
     recTypeLst = new List<SelectOption>(); 
     recLst = new List<RecordType>();  
       recTypeLst.add(new SelectOption('','---Select---'));
    List<RecordTypeInfo> infos = Prospect__c.sobjectType.getDescribe().getRecordTypeInfos();
    set<id> recTypeIdLst = new Set<Id>();
    // List<RecordType> recLst =  [select id,name from RecordType where sobjectType = 'Prospect__c' and isActive = true];
    for(RecordTypeInfo rec : infos)
    {
        if(rec.isAvailable() && !rec.isMaster()){
            recTypeLst.add(new SelectOption(rec.getRecordTypeId(),rec.getName()));
            recTypeIdLst.add(rec.getRecordTypeId());
        }
        
    }
   recLst =  [select id,name,Description from RecordType where id=:recTypeIdLst and sobjectType = 'Prospect__c' and isActive = true];     
   leadId = System.currentPageReference().getParameters().get('ldId');   
   contactId = System.currentPageReference().getParameters().get('conId');
    if(contactId != null)
    {
      Contact con = [select id,name from contact where id=:contactId];
      contactName= con.name;        
    }
        
  }
  • December 24, 2021
  • Like
  • 0
write class and trigger to generate recipt why creating new passenger and to delete exting recipt create a new recipt when passenger   new amount is update 
Deal All,

Is there a way we can access current page URL, its query string and current request heards from Apex? I am looking to use it across LWC and screen flows to gather these information for furthe validations.

Thanks 
Hi, I was told to post this issue here after contacting Salesforce Support in the usual way.
-----

What happened?:
We're working with a customer and they've installed one of our products from the AppExchange. This package contains a collection of custom objects and fields, as well as some Apex Classes and Triggers. Our package relates to Opportunities and Opportunity Products, via a custom Revenue Schedules object.

When logged in as a system administrator with the "Modify All Data" permission, everything works correctly (as expected). The Revenue Schedules change, which updates the Opportunity Product information as expected (Sales Price and Total Price specifically).

When logged in as another user in the system with a different profile, they are unable to trigger an update on the Opportunity Product despite having full access to the object and the fields. All necessary fields are read/write and the object access is correct. When logged in as another user, I am also able view the record I need to edit, so I am absolutely certain these is no access issue. When our code triggers, the update to the Opportunity Product object never occurs, and we can't understand why.

We attempted to add the "Modify All Data" permission to a different profile for testing and debugging, but we are also unable to save this permission.

Our app works perfectly for all users in other environments with exactly the same configuration.

Expected Outcome:
When a user manipulates the custom Revenue Schedules object records, the Opportunity Product Sales Price and Total Price should change and the Opportunity Amount should update. This is only working for System Administrators, no other users.

Error Messages:
There is no error message, instead, the process is bypassed unexpectedly.

Does anyone have any idea as to why this issue might be occurring?

Hi,

I have to two loop values in one loop how it is possible?

Ex:

List<Account> accList = [SELECT Id, Name FROM Account LIMIT 10];
List<Account> accList2 = [SELECT Id, Name FROM Account LIMIT 9 OFFSET 1];

for(){
String s = accList.name  + accList2.Name;
}

i want to pass in for loop one by one how it will be possible please help me.

Thanks,
Dhilip Dussa

 global with sharing class SystemEmailCompCtrl {
 public boolean isExternal {
    get {
      User user = [SELECT ContactId FROM User WHERE Id =:UserInfo.getUserId() AND IsActive=true WITH SECURITY_ENFORCED];
      if(user.ContactId != null){
        return true;
      }else {
        return false;
      }
    }
  }
  
  public boolean isAttachmentEnabled {
    get {
      return GNT.KeyValueStoreHelper.getBooleanValue('EnableEmailAttachment',true) == null ? false : GNT.KeyValueStoreHelper.getBooleanValue('EnableEmailAttachment',true);
    }
  }
  
  global class ResultWrapper{
    public Id id;
    public String name;
    public String email;
    public String collaborationType;
    public Integer memberCount;
    public String objType;
    public ResultWrapper(Sobject sobj,Boolean isGroup){
      this.id = (Id)sobj.get('Id');
      String strId = String.valueof(Id);
      if(strId.startsWith('005')){
        this.objType = 'User';
      }else {
        this.objType = 'Contact';
      }
      
      this.name = (String)sobj.get('Name');
      if(isGroup){
        this.collaborationType = (String)sobj.get('CollaborationType');
        this.memberCount = (Integer)sobj.get('MemberCount');
      }
      else{
        this.email = (String)sobj.get('Email');
      }
    }
  }
  
  @RemoteAction
  global static List<ResultWrapper> getRecordsNew(Map<String, Object> paramatersMap ){
    System.debug('In getRecordsNew::');
    String searchString = (String)paramatersMap.get('searchString');
    String objectApiName = (String)paramatersMap.get('objectApiName');
    String fieldToDisplay = (String)paramatersMap.get('fieldToDisplay');
    String fieldBindToTarget = (String)paramatersMap.get('fieldBindToTarget');
    String fieldToFilter = (String)paramatersMap.get('fieldToFilter');
    String selectedRecordIds = (String)paramatersMap.get('selectedRecordIds');
    
    
    String searchType = (String)paramatersMap.get('searchType');
    Boolean isExternalUser = false;
    if(searchType.trim().equals('External')){
      isExternalUser = true;
    }
    List<Sobject> records;
    List<ResultWrapper> resultWrappers = new List<ResultWrapper>();
    try{
      
      List<String> lstSelectedRecordIds = selectedRecordIds.split(',');
      Set<String> filteredRecordIds = new Set<String>();
      if(lstSelectedRecordIds.size()>0){
        filteredRecordIds.addall(lstSelectedRecordIds);
      }
      
      if(filteredRecordIds.size()>0){
        System.debug('filteredRecordIds::'+filteredRecordIds);
        
        // segrgate ids as user or contact ids
        List<Id>filteredUserIds = new List<Id>();
        List<Id>filteredContactIds = new List<Id>();
        for (String filteredRecordId : filteredRecordIds) {
          System.debug('filteredRecordId::'+filteredRecordId);
          if(filteredRecordId.startsWith('005')){
            filteredUserIds.add(filteredRecordId);
          }
          if(filteredRecordId.startsWith('003')){
            filteredContactIds.add(filteredRecordId);
          }
        }
        Set<String>filteredEmails = new Set<String>();
        List<User>filteredUserDetails = filteredUserIds.size()>0 ? [SELECT Email FROM User WHERE Id IN:filteredUserIds WITH SECURITY_ENFORCED] : null;
        List<Contact>filteredContactDetails = filteredContactIds.size()>0 ? [SELECT Email FROM Contact WHERE Id IN:filteredContactIds WITH SECURITY_ENFORCED] : null;
        if(filteredUserDetails != null && filteredUserDetails.size()>0){
          for(User user : filteredUserDetails){
            filteredEmails.add(user.Email);
          }
        }
        if(filteredContactDetails != null && filteredContactDetails.size()>0){
          for(Contact contact : filteredContactDetails){
            filteredEmails.add(contact.Email);
          }
        }
        system.debug('filteredEmails::'+filteredEmails);
      }
      String userQuery = '';
      
            if(objectApiName.toLowercase() == 'contact'){
        String contactQuery = 'SELECT Id,Name,Email FROM Contact WHERE Id NOT IN :filteredRecordIds AND '+fieldToFilter+' LIKE \'%'+string.escapeSingleQuotes(searchString)+'%\' AND Email != NULL WITH SECURITY_ENFORCED';
        List<Sobject> contacts = Database.query(contactQuery.escapeHtml4());
        for(Integer count=0;count<contacts.size();count++){
          resultWrappers.add(new ResultWrapper(contacts[count],false));
        }
      }
    }
    catch(Exception e){
      System.debug(e.getMessage()+ ' - line no: '+e.getLineNumber());
    }
    
    return resultWrappers;
  }
Issue description:
My code is working properly when it comes to updating the datatable. Pagination also works fine. Issue is, every page i am displaying 50 records. Now if i go to my second page, update any record and save, the record is getting saved BUT the page is refreshing back to the first page. Is there any way that if any record from 2nd page is updated, after hitting save button, the page refreshes back to the same page and display the updated data instead of refreshing back to the main page.
User-added imageUser-added imageUser-added imageHTML:

Hi everyone,

I am new with Apex and and still have a lot to learn. I have built a schedulable class that should check some records and perform an update in the same object (quite simple). Problem is the test class that doesn't get enough code coverage. I have used the anonymous window and records are created. Problem is the UPDATE which is not performed.

here the class:



Apex Class

global class UpdateRollingAvgMonthlyRevenueJob implements Schedulable {
    global void execute(SchedulableContext ctx){
        //Query Acct Revenue Month that needs to be updated
    List<Acct_Revenue_Month__c> acctRevenueMonthList = [SELECT Id, Rolling_AvgMonRev__c, Rolling_AvgMonRevforFormula__c 
                                                            FROM Acct_Revenue_Month__c
                                                            WHERE IsAvgMonthRollCompare__c = TRUE ];
       
        List<Acct_Revenue_Month__c> acctRevenueMonthListToBeUpdated = new List<Acct_Revenue_Month__c>();
        
        if(!acctRevenueMonthList.isEmpty()){
            for(Acct_Revenue_Month__c arm : acctRevenueMonthList){
                Acct_Revenue_Month__c AcctRevMonth = new Acct_Revenue_Month__c ();
                AcctRevMonth.Rolling_AvgMonRevforFormula__c = arm.Rolling_AvgMonRev__c;
acctRevenueMonthListToBeUpdated.add(arm);                
            }
            update acctRevenueMonthListToBeUpdated;
        }
    }
}



Test Class


@isTest
private class UpdateRollingAvgMonthlyRevenueTest {
    public static String CRON_EXP = '0 0 0 15 3 ? 2022';
    static testmethod void testScheduledJob() {
        
         Date firstDayOfMonth = System.today().toStartOfMonth();
    
        //Create acct Revenue Month
        Acct_Revenue_Month__c arm = new Acct_Revenue_Month__c();
        arm.Name = 'TestAcct';
        arm.Rolling_AvgMonRevforFormula__c = 1; 
        
        insert arm;
        
        arm.Rolling_AvgMonRevforFormula__c = arm.Rolling_AvgMonRev__c;
        update arm;
        
        Test.startTest();
        // Schedule the test job
        String jobId = System.schedule('ScheduledApexTest',
           CRON_EXP,
            new UpdateRollingAvgMonthlyRevenueJob());
        // Stopping the test will run the job synchronously
        Test.stopTest();   
        
        arm = [SELECT Name,Tier__c,Company_Group_Monthly__c,Rolling_AvgMonRevforFormula__c,Rolling_AvgMonRev__c,LastModifiedDate
                                FROM Acct_Revenue_Month__c WHERE id = :arm.Id];
        
        system.assertNotEquals(null, arm.Rolling_AvgMonRevforFormula__c, 'This record has been modified');
        arm.Rolling_AvgMonRevforFormula__c = arm.Rolling_AvgMonRev__c;
        update arm;
    }
}

  • November 05, 2021
  • Like
  • 0
Hi,
I have a custom object: Team Member. It is looking up to another custom object Vendor_Contract (Vendor Contract to Team Member is 1 to many relationship). My trigger accurately restricts users to create mulitple Team Members with total allocations exceeding above 100 % for a particular Vendor Contract. For example Vendor 1 has 3 Team Members. The allocation sum of these 3 team members cant exceed 100%.
I have written the following Test class which is unable to provide coverage. Not sure how to handle this. Any help will be definitely helpful.

 @isTest static void TestCreateNewLabContAllocMoreThan100(){
        List<Team_Member__c> tms= New List<Team_Member__c>();

        Vendor_Contract__c ven= New Vendor_Contract__c(Name='Test Vendor');
        Insert ven;

        Insert team;
        for(Integer i=0; i<200; i++){
            Team_Member__c tm= New Team_Member__c(Vendor_Contract__c=ven.id, Allocation_to_Team__c=1);
            tms.add(tm);
        }
         
        String message;
        Test.startTest();
        try{
            insert tms;
        }catch(Exception e){
            message = e.getMessage();
        }
        Test.stopTest();   
        List<Vendor_Contract__c> venCont = [SELECT Id, (SELECT Id, Allocation_to_Team__c FROM Team_Members__r) FROM Vendor_Contract__c WHERE Id =:ven.Id];
        for(Team_Member__c tm:venCont.Team_Members__r){
            system.assertEquals(tm.Allocation_to_Team__c, 1);            
        }
        
    } 
I have tried Where this field used? button but it didn't work in this scenario. Could someone please help me in this?
  • November 05, 2021
  • Like
  • 0
List<order> odr = [select id,odname from order where odname =:'xyz'];
                    if(odr.size() > 0 && insodr.id != null)
                    {
                        for(order od:odr)
                        {
                         od.OpportunityId = insodr.id;
                         update od;
                        }
                         
                    }
 
Hi Guys,

I have a field which has values separated by commas. I have queried this field and stored in a list. The list has only one record. How do I separate the values in the field?
start time__c + Endtime__c--time field 
formula field total hours =???
Failed to save lightningDataServices.cmp: No INTERFACE named markup://flexipage:availableForAllpages foundNo INTERFACE named markup://flexipage:availableForAllpages found: Source
I finished the customization of the home page on trailhead and when tried to verify, I got the message - 

Step not yet complete in My Trailhead Playground 1
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: PSKSTGMB
Please tell me how you can make an archiver of records and objects into an external database and then delete them from Salesforce? Let's say your task is to delete records from 5 objects whose creation date is less than 2019. How to think through the logic of collecting all child records and objects? How to avoid duplicates and intersections?
Hi all,

I have an object name hotel rooms with list of rooms and another object called reservations,  in the reservation object i have a field called  rooms as lookup field to hotel rooms,when we access the  rooms i want to update the status as not active and make it not accessable using look up field.