• Rajesh_Kumar
  • NEWBIE
  • 60 Points
  • Member since 2017


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 14
    Replies
I am  having Http callout class to post the data in third party class is working perfctly according to my requirement , but the thing as i am new on Devlopment so i need to convert this class into the batch class how can i convert this can any please help me i am just stuck on this.........
I am trying to handle the success save event of LDS saveRecord method. I need only proper Id from the new record response. In DESKTOP it's working fine whereas in Mobile/Tablet i am getting improper id like 003___Mz01SPHkYQAX.

I enabled "Enable offline create, edit, and delete in Salesforce for Android and iOS" in my org. I don't want to disable it.

As per my understanding when I call the saveRecord method of LDS, the record has been added into the cache/draft before committing to the database. That's fine, but after committing the new record to database i am not receiving any event from LDS which is strange. I am expecting some event from the recordUpdated attribute of force:recordData. I cannot use the lightning:recordEditForm, lightning:recordForm because i don't want the standard UI for input fields. Here is my component

newContact.cmp
<aura:component >
    <aura:attribute name="newContact" type="Object"/>
    <aura:attribute name="simpleNewContact" type="Object"/>
    <aura:attribute name="newContactError" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <force:recordData aura:id="contactRecordCreator" 
                      layoutType="FULL"
                      mode="EDIT"
                      targetRecord="{!v.newContact}"
                      targetFields="{!v.simpleNewContact}"
                      targetError="{!v.newContactError}"
                      recordUpdated="{!c.handleRecordUpdated}"/>
    <div class="Create Contact">
        <lightning:card iconName="action:new_contact" title="Create Contact">
            <div class="slds-p-horizontal--small">
                <lightning:input aura:id="contactField" label="First Name" value="{!v.simpleNewContact.FirstName}"/>
                <lightning:input aura:id="contactField" label="Last Name" value="{!v.simpleNewContact.LastName}"/>
                <lightning:input aura:id="contactField" label="Title" value="{!v.simpleNewContact.Title}"/>
                <br/>
                <lightning:button label="Save Contact" variant="brand" onclick="{!c.handleSaveContact}"/>
            </div>
        </lightning:card>
    </div>

    <!-- Display Lightning Data Service errors -->
    <aura:if isTrue="{!not(empty(v.newContactError))}">
        <div class="recordError">
            {!v.newContactError}</div>
    </aura:if>
</aura:component>

newContactController.js
 
({
    doInit: function(component, event, helper) {
        // Prepare a new record from template
        component.find("contactRecordCreator").getNewRecord(
            "Contact", // sObject type (objectApiName)
            null,      // recordTypeId
            false,     // skip cache?
            $A.getCallback(function() {
                var rec = component.get("v.newContact");
                var error = component.get("v.newContactError");
                if(error || (rec === null)) {
                    console.log("Error initializing record template: " + error);
                    return;
                }
                console.log("Record template initialized: " + rec.sobjectType);
            })
        );
    },

    handleSaveContact: function(component, event, helper) {
        component.find("contactRecordCreator").saveRecord(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                // record is saved successfully
                var resultsToast = $A.get("e.force:showToast");
                console.log(JSON.stringify(component.get("v.simpleNewContact")));
                resultsToast.setParams({
                    "title": "Saved on "+saveResult.state,
                    "message": "The record was saved under "+component.get("v.simpleNewContact.Id")
                });
                resultsToast.fire();

            } else if (saveResult.state === "INCOMPLETE") {
                // handle the incomplete state
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                // handle the error state
                console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        });
    }, 
    handleRecordUpdated: function(component, event, helper) {
        /**Here no events fired when saving new record from LDS**/
        var eventParams = event.getParams();
        console.log(eventParams);
        alert(eventParams.changeType);
    }
})

Let me know if you have any workaround for this issue.
​​​​​​​
Thanks
Hi All,

I created a new field in user with the data type number am trying to update the field called Total License from user license object .

to acomplish this i wrote a bacth class.But its not updating this field.

Kindly let mw know ,Where i do changes
Batch Class:
global class totallicensecount implements Database.Batchable<SObject>{
Map<ID,String> License= New Map<ID,String>();
Map<string,Integer> License1= New Map<string,Integer>();
list<user> query1=new list<user>();
set<string> setuserlicense=new set<string>();
list<user> listofuser=new list<user>();

        
        global Database.QueryLocator start(Database.BatchableContext bc){
                string query='select Id,name,TotalLicenses from Userlicense'; 
                query+='limit 1';       
                return Database.getQueryLocator(query);
        
        }
        

        global void execute(Database.BatchableContext bc,list<Userlicense> scope){
        
                for(Userlicense us:scope){
                License1.put(Us.Name,us.TotalLicenses);
                setuserlicense.add(us.name);
                }
            
                    query1=[select Id,name,profile.Userlicense.name,Profile.UserLicense.TotalLicenses,Type__C,Total_license_count__c from user where profile.Userlicense.name in :setuserlicense];
                    for(user us1:query1){
                    us1.Total_license_count__c=License1.get(us1.profile.Userlicense.name);
                    listofuser.add(us1);                   
                   
                }
            
        IF(listofuser.size()>0){
        
        update listofuser;
        
        }
}



global void finish (Database.BatchableContext bc){
}



}


 
I am  having Http callout class to post the data in third party class is working perfctly according to my requirement , but the thing as i am new on Devlopment so i need to convert this class into the batch class how can i convert this can any please help me i am just stuck on this.........