• Annu Choudhary
  • NEWBIE
  • 100 Points
  • Member since 2018

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 10
    Likes Given
  • 0
    Questions
  • 19
    Replies
Hi Friends,
I was trying a test code to insert 50,000 records using the below code, its throwing the limit exception related to dml rows of 10000 reached.

My question is since I specified  false as below
Database.SaveResult[] srList = Database.insert(lstContacts, false);
is this code suppose to insert at least 10000 records, but did'nt do it.

Let me know your comments.


My code below
List<Contact> lstContacts = new List<Contact>();
for(Integer x = 0; x<50000; x++ ){
    Contact con = new Contact(LastName= 'Keller'+x, FirstName='Helen'+x);
    lstContacts.add(con);
}
Database.SaveResult[] srList = Database.insert(lstContacts, false);

for (Database.SaveResult sr : srList) {
    if (sr.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted account. Account ID: ' + sr.getId());
    }
    else {
        // Operation failed, so get all errors                
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Account fields that affected this error: ' + err.getFields());
        }
    }
}

Thanks
JG
 
Hii Friends,
I want code for upsert records
I have oject Timesheet__c custom object.
Which has following filed.
Name
Month__c(Master_detail with Month__c object)
Resource__c(Lookup with Resource__c object)

i want code for if the Timesheet for that Month is already exist then update that records if not then create new record.
this is my code
Timesheet__c ts=new Timesheet__c();
                    ts.Month__c=new_records3.Id;
                    ts.Resource__c=currentRecord.Resource__c;
                    List<Timesheet__c> tlist=new List<Timesheet__c>();
                    tlist=[SELECT ID,Name,Month__r.Name,Resource__r.Name 
                           FROM Timesheet__c
                           WHERE Month__r.Name=: new_records3.Name AND Resource__r.Name=:currentRecord.Resource__r.Name];
                    if(tlist.size()>0){
                        for(Timesheet__c t:tlist){
                            update ts t.ID;
                        }
                        
                    }
                    else
                        insert ts;

Above not updating existing records.It creating new records.
Please help me as soon as possible. Its very urgent
Thanks in advance
Hi All,
     I had a LWC component which simply update an child (contact) record using Inline Edit. I am getting this error : Uncaught (in promise) TypeError: Cannot read property 'message' of undefined at eval (lwc_utils.js:4). I am using this LWC component Account record detail page to display associate child (contact) records. Please any one guide me how to fix this issue. 

Unable to edit this record using inline edit. Got this error
Error
Apex Class: ContactController
----------------------------------------- 
public with sharing class ContactController {
    @AuraEnabled(Cacheable = true)
    public static List<Contact> getRecords(String recordId) {        
       return [SELECT Name, Email,Phone,Maximum__c,Minimum__c FROM Contact WHERE AccountId =: recordId];
    }

    @AuraEnabled
    public static void saveContacts(List<Contact> conList){
        Insert conList;        
    } 
}
Java Script: 
----------------
import { LightningElement, track, wire, api } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import CONTACT_OBJECT from '@salesforce/schema/Contact';
import ID_FIELD from '@salesforce/schema/Contact.Id';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName';
import EMAIL_FIELD from '@salesforce/schema/Contact.Email';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
import MAX_FIELD from '@salesforce/schema/Contact.Maximum__c';
import MIN_FIELD from '@salesforce/schema/Contact.Minimum__c';
import getRecords from '@salesforce/apex/ContactController.getRecords';
import saveContacts from '@salesforce/apex/ContactController.saveContacts';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { refreshApex } from '@salesforce/apex';
import { updateRecord } from 'lightning/uiRecordApi';

const columns = [
    { label: 'Name', fieldName: 'Name' , type: 'Text', editable: true},
    { label: 'Email', fieldName: 'Email', type: 'Email', editable: true },
    { label: 'Phone', fieldName: 'Phone', type: 'Phone', editable: true },
    { label: 'Maximum', fieldName: 'Maximum__c', type: 'number', editable: true },
    { label: 'Minimum', fieldName: 'Minimum__c', type: 'number', editable: true },
];

export default class DatatableBasic extends NavigationMixin(LightningElement) {
@api recordId;
@track data;
@track contactList = [];
@track draftValues = []; 
@track firstName = FIRSTNAME_FIELD;
@track lastName = LASTNAME_FIELD;
@track email = EMAIL_FIELD;
@track phone = PHONE_FIELD;
@track max = MAX_FIELD;
@track min = MIN_FIELD;
@track columns = columns;
@track tableLoadingState = true;
@track noRecordsFound = true;
error;
wiredDataResult;

con = {
    FirstName : this.firstName,
    LastName : this.lastName,
    Email : this.email,
    Phone : this.phone,
    AccountId : this.recordId,
    Maximum__c : this.max,
    Minimum__c : this.min,
    key : ''
}

concCellChange(event){
    console.log(event.detail);
}

handleSave(event) {

    const fields = {};
    fields[ID_FIELD.fieldApiName] = event.detail.draftValues[0].Id;
    fields[FIRSTNAME_FIELD.fieldApiName] = event.detail.draftValues[0].FirstName;
    fields[LASTNAME_FIELD.fieldApiName] = event.detail.draftValues[0].LastName;
    fields[EMAIL_FIELD.fieldApiName] = event.detail.draftValues[0].Email;
    fields[PHONE_FIELD.fieldApiName] = event.detail.draftValues[0].Phone;
    fields[MAX_FIELD.fieldApiName] = event.detail.draftValues[0].Maximum__c;
    fields[MIN_FIELD.fieldApiName] = event.detail.draftValues[0].Minimum__c;

    const recordInput = {fields};

    updateRecord(recordInput)
    .then(() => {
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Success',
                message: 'Contact updated',
                variant: 'success'
            })
        );
        // Clear all draft values
        this.draftValues = [];
        // Display fresh data in the datatable
        return refreshApex(this.recordInput);
    })
    .catch(error => {
        this.message = undefined;
        this.error = error;
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Error creating record',
                message: error.body.message,
                variant: 'error'
            })
        );
        console.log("error", JSON.stringify(this.error));
    });
}

@wire(getRecords , { recordId: '$recordId' })  
    wiredRecordsMethod(result) {
        this.wiredDataResult = result;
        if (result.data) {
            this.data = result.data;
            this.error = undefined;
            if(this.data.length > 0){
                this.noRecordsFound = false;
            }
            else{
                this.noRecordsFound = true;
            }
   
        } else if (result.error) {
            this.error = result.error;
            this.data = undefined;
        }        
    }
}
HTML:
---------
<template>
    <lightning-card title="Contacts" icon-name="standard:Contact" > <br/>
        <div style="width: auto;">
            <template if:true={data}>   
            <div class="slds-p-around_medium lgc-bg" style="height: 300px;">
                <lightning-datatable
                        key-field="id"
                        data={data}
                        columns={columns}
                        show-row-number-column="true"
                        hide-checkbox-column="true"
                        oncellchange={concCellChange}
                        onsave={handleSave}
                        draft-values={draftValues} >
                </lightning-datatable>
                <template if:true= {noRecordsFound}>
                    --No Contact Records Found--
                </template>
            </div>  
            </template>
            
        </div>
    </lightning-card>   
</template>

Thanks
Siva

 
Toast message works when i work from standalone LEX component, however when i save the record from the lightningApp the toast messages are not getting fire.

I know there is a limitation since we can not fire toast events from classic and app, 

I am looking out for an workaround here. Appreciate your help


Below is my controller.
onSave : function (component, event, helper) {
        helper.saveRec(component, event, helper);
    },
Helper :
 
saveRec:function(component, event, helper) {
        var gbmObj= component.get("v.newGBMPlan");
        var action = component.get("c.creatGBMRecord");
        if(component.get("v.recId")=="new")
        {
            action.setParams({
                "gbm": gbmObj ,
                "recId":component.get("v.recId"),
                
            });
        }
        else
        {
            action.setParams({
                "gbm": gbmObj ,
                "recId":component.get("v.recId"),
                
            });
        }
        action.setCallback(this,function(response){
            if (response.getState() === "SUCCESS") {
                //alert("Record Created/Updated Successfully");
                //window.close();
                
               // var toastEvent = $A.get("e.force:showToast");
              
                  helper.showToast({
                    title: "Record Created/Updated Successfully",
                    message: " ",
                    type: "success"
                });
             //toastEvent.fire();

Lightning App
<aura:application extends="force:slds" access="GLOBAL" >
    <aura:dependency resource="markup://force:showToast" type="EVENT"></aura:dependency>
	 <c:SC_Plans/>
  </aura:application>


 
Hi,
On Event object there are two fileds StartDateTime and EndDateTime,
on the aura component (not on the controller) how can i check that enddatetime of the event is greater than the startdatetime by 2 days.
then i want ot display Multiday event.
Thanks
Hi...! need to generate the salesforce simple json....i had embeded a page in the other page.. and trying to generate the json .. 

Page:1:
<apex:page controller="controllertest1">
  <apex:form >
   Enter Name:<apex:inputText value="{!statedet.stateName}"/>
  </apex:form>
</apex:page>
Page:2  : called page1 in page2
<apex:page controller="controllertest1">
 <apex:include pageName="testpage1"/>
  <br/>
  <apex:form >
   <apex:commandButton value="JSON GENERATOR"  action="{!genereatejson}" reRender="tm" />
  <br/>
   <apex:outputLabel id="tm"> {!jsonstrng}</apex:outputLabel>
  </apex:form>
</apex:page>

Commoncontroller:
public class controllertest1{
   public statedetails statedet{get;set;}
   public string jsonstrng{get;set;}
   public  controllertest1(){
     string  teststring= ' { "sucess":1,"data": {"stateName": "Andrapradesh",  "value": "apx" ,"rating":5 } } ';
     Map<String, Object> maptest =   (Map<String, Object>) JSON.deserializeUntyped(teststring);
     Object ob = (Object)maptest.get('data');
     String srlze  = System.JSON.serialize(ob);
     statedet= (statedetails)System.JSON.deserialize(srlze,statedetails .class);
    }
 public void genereatejson(){
          JSONGenerator gen = JSON.createGenerator(true);
          gen.writeStartObject();
          gen.writeStringField('stateName',statedet.stateName);
          gen.writeEndObject();
          jsonstrng = gen.getasString();
   }
      //wrapperclass
       public  class statedetails{
       public string stateName{get;set;}
       public string value{get;set;}
       public integer rating{get;set;}
       }
}

Note: After editing the input and clicking on the Button, iam not getting the changed  dynamic format . 
thanks 
deepika
 
Here is what i have done...
Messaging.SendEmailResult[] results;
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setToAddresses(new String[] {ldOwnerMail});
message.setTemplateId([select id from EmailTemplate where DeveloperName='LeadsNewassignmentnotificationSAMPLE'].id);
message.setTargetObjectId(lead.OwnerId);

message.setSaveAsActivity(false);
results = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{message});
How to pass recordId here so Emailtemplate can take it and show further details (Name,Company).


Template is look alike is--
** NEW LEAD STATUS CHANGE NOTIFICATION ***

The following lead's status has been changed.

Lead Name: {!Lead.Name}

Company: {!Lead.Company}

Here is the Lead Detail: {!Lead.Link}

 
Here is my code for a separate section and a column.I need to 2 two columns as i have many field to show on that section of layout.
Can anyone help how to divide a section in two columns by apex.I am using Metadata API currently.
if(layout.layoutSections==null)
            layout.layoutSections = new List<MetadataService.LayoutSection>();
        MetadataService.LayoutSection newLayoutSection = new MetadataService.LayoutSection();
        newLayoutSection.customLabel = true;
        newLayoutSection.detailHeading = true;
        newLayoutSection.editHeading = true;
        newLayoutSection.label = 'Keyword fields';
        newLayoutSection.style = 'TwoColumnsLeftToRight';}

 
hi ,

I have to create google chart from apex class and insert the chart into attachement.

Thanks.
I have to take input in vf page using html tag <input type> then capitalize the input and display it in another vf page. How should I approach?