Dynamic mass record.html
=================
<template>
<lightning-card title="Opportunity's Transfer to Users Model 2">
<lightning-combobox
name="From User"
label="From User"
value={value1}
placeholder="Select Progress"
options={userop}
onchange={fromChange} ></lightning-combobox>
<lightning-combobox
name="To User"
label="To User"
value={value2}
placeholder="Select Progress"
options={userop}
onchange={toChange} ></lightning-combobox>
<lightning-combobox
label="Select Object"
value={value3}
placeholder="Select Progress"
options={objectsName}
onchange={toselectobjecthandler} ></lightning-combobox>
<br/>
<lightning-button label="Tranfer" variant="Brand" onclick={handleTransfer}></lightning-button>
</lightning-card>
</template>
Dynamic mass record.js
=================
import { LightningElement,wire} from 'lwc';
import user1 from '@salesforce/apex/guru_Apexclass.user1';
import model2Method from '@salesforce/apex/guru_Apexclass.model2Method';
import transferrecords1 from '@salesforce/apex/guru_Apexclass.transferrecords1';
export default class Opty_transfer extends LightningElement
{
value1='';
value2='';
value3='';
useroptions=[];
objectsName=[];
returnfromobject=''
@wire(user1)guru({data,error}){
if(data)
{
for(let i=0;i<=data.length;i++)
{
this.useroptions=[...this.useroptions,{label:data[i].Name,value:data[i].Id}];
console.log('user options-->',this.useroptions);
}if(error)
{
console.log(error);
}
}
}
@wire(model2Method)chandu({data,error}){
if(data)
{
this.objectsName = data.map(name => ({ label: name, value: name }));
console.log('ObjName:'+this.objectsName);
}
if(error){
console.log(error);
}
}
toselectobjecthandler(event){
this.value3=event.target.value;
alert(this.value3);
console.log('userid--->',this.value3);
}
fromChange(event){
this.value1=event.detail.value;
alert(this.value1);
console.log('userid--->',this.value1);
}
toChange(event){
this.value2=event.detail.value;
alert(this.value2);
console.log('userid--->',this.value2);
}
get userop()
{
return this.useroptions;
}
//transferrecords1(string objectName, string fromuser,string touser)
handleTransfer(){
transferrecords1({objectName:this.value3,fromuser:this.value1,touser:this.value2}).then(result =>{
this.returnfromobject=result;
console.log('return-->',this.returnfromobject);
}).catch(
error =>{
console.log(error);
}
);
}
}
Apex class:-
-------------
public with sharing class guru_Apexclass {
@AuraEnabled(cacheable=true)
public static List<Opportunity> getOpportunitys() {
return [select Id,Name,StageName,CloseDate,LeadSource,ownerId from Opportunity where ownerId =:userinfo.getUserId() ];
}//
@AuraEnabled(cacheable=true)
public static List<user> user1(){
return [select id,Name from user];
}
@AuraEnabled
public static string UpdatedOpptyOwnerId(List<Id> lstId,string userId2){
List<Opportunity> lstOpp=[select Id,Name,ownerId from Opportunity where Id In:lstId];
list<Opportunity> newlist=new list<Opportunity>();
for(Opportunity opp:lstopp)
{
opp.ownerId=userId2;
newlist.add(opp);
}
update newlist;
return 'records updated successfully';
}
@AuraEnabled(cacheable=true)
public static List<String> model2Method(){
List<Schema.SObjectType> objectTypes = Schema.getGlobalDescribe().Values();
List<String> objectNames = new List<String>();
for(Schema.SObjectType objectType : objectTypes) {
objectNames.add(objectType.getDescribe().getName());
}
return objectNames;
}
@AuraEnabled
public static string transferrecords1(string objectName, string fromuser,string touser){
if(objectName!= ' ')
{
String fieldName = 'OwnerId';
//String objectName = 'Account';
// String fieldValue = '0051e000002xVEnAAM';
// string queryString = '0055g00000FWLshAAH';
String soqlQuery = 'SELECT Id, OwnerId FROM ' + objectName + ' WHERE OwnerId = \'' + fromuser + '\'';
List<SObject> records = Database.query(soqlQuery);
for (SObject record : records) {
record.put(fieldName, touser);
}
update records;
return 'record updates successfully';
}else {
return 'record error';
}
}
}
Comments
Post a Comment