• anshiSFDC
  • NEWBIE
  • 69 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 13
    Replies
Hi everyone tried below trigger which is working fine but testclass failed,can someone help me out.

Trigger:
//when opportunity is inserted opportunityLineItem with one product associated should insert
trigger Insertingoppandoppline on Opportunity (after insert) {
 Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where  IsStandard = true limit 1];
    
    Product2 prd1 = new Product2 (); // ----> Create  product
    prd1.Name='myproduct';
    insert prd1;
    
    PricebookEntry pbe1 = new PricebookEntry ();  //------->Create PriceBookEntry
    pbe1.Product2ID=prd1.id;
    pbe1.Pricebook2ID=standardPb.id;
    pbe1.UnitPrice=50;
    pbe1.isActive=true;
    insert pbe1;
    
    List<OpportunityLineItem>  oplist=new List<OpportunityLineItem>(); //-->Create List to store OpportunityLineItem
    
    for(Opportunity opp: Trigger.New)
    {
        OpportunityLineItem oppli = new OpportunityLineItem(); //---->Create OpportunityLineItem.
        oppli.PricebookEntryId=pbe1.Id;
        oppli.OpportunityId = opp.Id;
        oppli.Quantity = 5;
        oppli.TotalPrice = 10.0;
       oplist.add(oppli);
    } 
    insert oplist; //----->insert OpportunityLineItem
}
testclass:
@isTest
public class Testinsertoppandoppline {
@isTest
    static void invoke(){
       PricebookEntry PBE=[select id from PricebookEntry limit 1 ];
Opportunity opp= new Opportunity();
opp.name='testOpp';
opp.closeDate=system.today()+20;
opp.stageName='Qualification';
try{
insert opp;
}
catch(Exception e){
System.debug(e);
}

List<opportunitylineitem> opppro = new opportunitylineitem[]{new opportunitylineitem(UnitPrice=10000.00, Quantity=10, opportunityid=opp.id, pricebookEntryId=PBE.id),new opportunitylineitem(UnitPrice=10000.00,     Quantity=10,  opportunityid=opp.id, pricebookEntryId=PBE.id),new opportunitylineitem(UnitPrice=10000.00,     Quantity=10,  opportunityid=opp.id, pricebookEntryId=PBE.id),new opportunitylineitem(UnitPrice=10000.00,     Quantity=10,  pricebookEntryId=PBE.id, opportunityid=opp.id)};
insert opppro;

    }
}
Hi evryone tried  below code and testclass able to cover 80% how to cover error message.
Trigger:
//write a trigger only system administrator should delete the tasks(if system administartor means delete the recrd if not show error message)
trigger userdeletetasks on Task (before delete) {
id profileid=userinfo.getProfileId();
    profile profilname=[select Name from Profile where id=:profileid];
    for(task t:trigger.old){
        if(profilname.Name!='System Administrator'){
            t.adderror('no access for user');
        }
    }
  
}

Testclass:
@isTest
public class Testuserdeletetasks {
@isTest
    static void call(){
        
      task t=new task();
        t.Subject='subtask';
        insert t;
         Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
       
            try{
                delete t;
            }catch(Exception ex){
                system.debug('Exception');
               
                system.assert(ex.getMessage().contains('no access for user'),'no access for user');
            }    
        
        
    }
}

Thanks in Advance.
Hi everyone how to add colors to the listviews in records based on the particular field.
Hi everyone,am trying to create a contact related to paritcular account in lightning .tried so far..,and embeded this component in accountrecord page ,but unable to save. can someone help me out .

Thanks in Advance.
apex:
public class QuickCreatecontact {
@AuraEnabled
    public static void createcontact(contact con,Id AccountId){
        con.AccountId=AccountId;
        insert con;
    }
}

component:
<aura:component controller="QuickCreatecontact" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="createcontact" type="contact"/>
    <aura:attribute name="accountId" type="string"/>
   <!-- <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>-->
    <div>
        <lightning:input type="text" name="{!v.createcontact.LastName}" label="Enter LastName" />
        <lightning:input type="text" name="{!v.createcontact.FirstName}" label="Enter firstName"/>
        <lightning:input type="phone" name="{!v.createcontact.phone}" label="Enter phone"/>
        
    </div>
    <div>
        <lightning:button label="save" variant="brand" onclick="{!c.dosave}"/>
     </div>
</aura:component>

js:
({
    dosave : function(component, event, helper) {
        var action=component.get("c.createcontact");
        action.setParams({
            con:component.get("v.createcontact"),
            Id:component.get("v.accountId")
        });
        action.setCallback(this,function(response){
            var state=response.getState();
           
            if(state==='SUCCESS'){
                var result=response.getReturnValue();
               alert('SUCCESS');
                
               
            }else if(state==='INCOMPLETE'){
                
            }
        });
        $A.enqueueAction(action);
    }
})
Hi every my scenario is to display the opportunity picklist in dropdown based on the picklist we select related records should display and if we click on update ,it should update ihave tried so far ,able to display picklist values but unable to display the records,below is the code

Apex:
public class opp1 {
    public List<SelectOption>options {set;get;}
    public List<opportunity>opportunities {set;get;}
    public List<oppwrapper>oppwraplist {set;get;}
    public string selected {set;get;}
    public opp1(){
       options=new List<SelectOption>();
        opportunities=new List<opportunity>();
        oppwraplist=new List<oppwrapper>();
        List<string>stagevalues=new List<string>{'prospecting','price/quote','need Analysis'}; 
            for(string op:stagevalues){
             SelectOption eachstage=new SelectOption(op,op);
               options.add(eachstage); 
            }
    }
    public void updatestages(){
        List<opportunity>opportunities=new List<opportunity>();
        for(oppwrapper ow:oppwraplist){
            if(ow.flag){
                ow.opp.stageName='selected';
                opportunities.add(ow.opp);
            }
        }
        
    }
    public class oppwrapper{
        public opportunity opp {set;get;}
         public boolean flag {set;get;}
    }    
    

}

vf:
<apex:page controller="opp1" >
    <apex:form >
        <apex:pageBlock >
            
      
           <apex:selectList value="{!selected}" size="1">
               <apex:selectOptions value="{!options}">
               </apex:selectOptions> 
               
            </apex:selectList>
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!opportunities}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.stageName}"/>
                <apex:column value="{!a.Amount}"/>
                
            </apex:pageBlockTable>
            </apex:pageBlockSection>
      
             <apex:pageBlockSection >
            <apex:commandButton value="update" action="{!updatestages}"/>
        </apex:pageBlockSection>
            
        </apex:pageBlock>
       
    </apex:form>
    
</apex:page>
Hi every one, In lightning is it is possible to display the toast message on the contact record page with the condition as name starts with Test.am able to display the toast message after the record is saved ,but i need to dispaly on the record page whose name starts with test.

Thanks in Advance
Hi everyone ,using aura component how to display the modal popup on the contact record whose name starts with test.

Thanks in advance
Hi everyone,below is the trigger and testclass  which i have written .
Trigger:
trigger updaterecords on Contact (before insert, before update, after insert, after update) {

List<Contact> conList =new List<Contact>();
    Set<Id> setid = new  Set<Id>();
  
    if(trigger.isBefore){
        system.debug('trigger before event');
        conList = trigger.new;
      
    }else if(trigger.isAfter){
         conList=trigger.new;
        for(Contact con:conList){
           setid.add(con.AccountId);
        }
        system.debug('setid ' + setid);
      
        List<Account> accList = [Select Id, Name, email__c From Account  Where Id=:setid];     
     
        if(trigger.isInsert){                   
          
             for(Contact c1:trigger.new){
                 for(Account a1:accList){
                     a1.email__c= c1.email;
                     update a1;
                 }
              }   
          
        }else if(trigger.isupdate){
            for(Contact c2:trigger.new){
                for(Account a2:accList){
                    a2.email__c= c2.email;
                    update a2;
                }
            }           
        }      
       
    }
}
Testclass:Is this is a crct way of writing the testclass for the above trigger,can someone help me in testclass

testclass:
@isTest
public class updaterecordsTest {
@isTest
    static void call(){
        Account a=new Account();
        a.name='testacc';
        a.Email__c='test@gmail.com';
        insert a;
        contact c=new contact();
        c.LastName='testlastName';
        c.FirstName='testfirstName';
        
        c.AccountId=a.id;
        insert c;
        Test.startTest();
        List<Account> acc=[select id,name,Email__C,(select id,LastName,firstName,Email from contacts)from Account where id=:a.id];
        //a.Email__c=c.Email;
        update acc;
        Test.stopTest();
    }
}
Hi everyone, can someonehelp how to write testclass for the below class

@RestResource(urlmapping='/v1/Accountmanager/')
global class Integration_Example {
@HttpGet
    //which is used to get the records or query the records
    global static Account doget(){
        //intilaise the object
       Account a=new Account();
        //get the req parameters in map
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id');
        //query the records
        a=[select id ,name from Account where id=:accid];
        return a;
    }
    @HttpDelete
    global static Account doDelete(){
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
        delete result;
        return result;
    }
   @Httppost
    //post method is used to create the record
    global static Account docreate(string name){
        Account a = new Account(name=name);
        insert a;
        return a;
    }
     @Httpput
    global static Account doupdate(string name){
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id'); 
        Account a = new Account(name=name, id=accid);
        update a;
        return a;
    }
}

Thanks in Advance
Hi everyone,the below is the class which i have written,tried testclass for that class is that crct way of writing testclass for that class.
class:
public class opp_paginationcontroller {
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public opp_paginationcontroller(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name,AccountId,Account.name,Amount,StageName,CloseDate,LastModifiedDate from Opportunity]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    // It Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Opportunity> getOpportunities() {
         return (List<Opportunity>) setCon.getRecords();
    }
}
testclass:
@isTest
public class Testopp_paginationcontroller {
@isTest
    static void invoke(){
       opportunity o=new opportunity();
        o.name='testopp';
        o.stageName='prospecting';
        o.closeDate=system.today();
        insert o;
        Test.startTest();
        opp_paginationcontroller opp=new opp_paginationcontroller();
       
        opp.refreshPageSize();
        opp.getOpportunities();
        Test.stopTest();
    }
}
Hi everyone,can someone help how to write testclass for the below code..
Thanks in Advance.

public class Displayrelatedlists {
    //1.list of wrapperclass
     public list<AccountContactWrapper> lstAccountContactWrapper { get; set; }
    public list<AccountContactWrapper> lstSelectedAccountContactWrapper { get; set; }
    //list for selecting the account records
    public list<account> selectedAccounts{get;set;} 

    public Displayrelatedlists () {
        //Allocating the memory for the list
        lstSelectedAccountContactWrapper = new list<AccountContactWrapper>();
        if(lstAccountContactWrapper == null) {
            //allocate memory for the wrapperlist
            lstAccountContactWrapper = new list<AccountContactWrapper>();
            for(account a:[select id,name,phone,(select id,name from contacts)from account limit 10]) {
                lstAccountContactWrapper.add(new AccountContactWrapper(a));
            }
        }
    }
 
    public void ProcessSelected() {
        lstSelectedAccountContactWrapper =new list<AccountContactWrapper>();
        selectedAccounts =new list<Account>();
        for(AccountContactWrapper wrapobj:lstAccountContactWrapper){
            if(wrapobj.isSelected==true) {
                selectedAccounts.add(wrapobj.acc);
            } 
        }
       
        for(Account acc:[select id,name,phone,(select id,name from contacts) from account where id in:selectedAccounts]) {
            lstSelectedAccountContactWrapper.add(new AccountContactWrapper(acc)); 
        }
             
    }
    public class AccountContactWrapper {
 
        public Account acc {get;set;}
        public boolean isSelected {get;set;}
   
        public AccountContactWrapper(account a) {
            acc = a;
            isselected=false;
        }
    }
}
Hi everyone, can someonehelp how to write testclass for the below class

@RestResource(urlmapping='/v1/Accountmanager/')
global class Integration_Example {
@HttpGet
    //which is used to get the records or query the records
    global static Account doget(){
        //intilaise the object
       Account a=new Account();
        //get the req parameters in map
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id');
        //query the records
        a=[select id ,name from Account where id=:accid];
        return a;
    }
    @HttpDelete
    global static Account doDelete(){
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
        delete result;
        return result;
    }
   @Httppost
    //post method is used to create the record
    global static Account docreate(string name){
        Account a = new Account(name=name);
        insert a;
        return a;
    }
     @Httpput
    global static Account doupdate(string name){
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id'); 
        Account a = new Account(name=name, id=accid);
        update a;
        return a;
    }
}

Thanks in Advance
Hi everyone,can someone help how to write testclass for the below code..
Thanks in Advance.

public class Displayrelatedlists {
    //1.list of wrapperclass
     public list<AccountContactWrapper> lstAccountContactWrapper { get; set; }
    public list<AccountContactWrapper> lstSelectedAccountContactWrapper { get; set; }
    //list for selecting the account records
    public list<account> selectedAccounts{get;set;} 

    public Displayrelatedlists () {
        //Allocating the memory for the list
        lstSelectedAccountContactWrapper = new list<AccountContactWrapper>();
        if(lstAccountContactWrapper == null) {
            //allocate memory for the wrapperlist
            lstAccountContactWrapper = new list<AccountContactWrapper>();
            for(account a:[select id,name,phone,(select id,name from contacts)from account limit 10]) {
                lstAccountContactWrapper.add(new AccountContactWrapper(a));
            }
        }
    }
 
    public void ProcessSelected() {
        lstSelectedAccountContactWrapper =new list<AccountContactWrapper>();
        selectedAccounts =new list<Account>();
        for(AccountContactWrapper wrapobj:lstAccountContactWrapper){
            if(wrapobj.isSelected==true) {
                selectedAccounts.add(wrapobj.acc);
            } 
        }
       
        for(Account acc:[select id,name,phone,(select id,name from contacts) from account where id in:selectedAccounts]) {
            lstSelectedAccountContactWrapper.add(new AccountContactWrapper(acc)); 
        }
             
    }
    public class AccountContactWrapper {
 
        public Account acc {get;set;}
        public boolean isSelected {get;set;}
   
        public AccountContactWrapper(account a) {
            acc = a;
            isselected=false;
        }
    }
}
Hi evryone tried  below code and testclass able to cover 80% how to cover error message.
Trigger:
//write a trigger only system administrator should delete the tasks(if system administartor means delete the recrd if not show error message)
trigger userdeletetasks on Task (before delete) {
id profileid=userinfo.getProfileId();
    profile profilname=[select Name from Profile where id=:profileid];
    for(task t:trigger.old){
        if(profilname.Name!='System Administrator'){
            t.adderror('no access for user');
        }
    }
  
}

Testclass:
@isTest
public class Testuserdeletetasks {
@isTest
    static void call(){
        
      task t=new task();
        t.Subject='subtask';
        insert t;
         Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
       
            try{
                delete t;
            }catch(Exception ex){
                system.debug('Exception');
               
                system.assert(ex.getMessage().contains('no access for user'),'no access for user');
            }    
        
        
    }
}

Thanks in Advance.
Hi everyone how to add colors to the listviews in records based on the particular field.
Hi everyone,am trying to create a contact related to paritcular account in lightning .tried so far..,and embeded this component in accountrecord page ,but unable to save. can someone help me out .

Thanks in Advance.
apex:
public class QuickCreatecontact {
@AuraEnabled
    public static void createcontact(contact con,Id AccountId){
        con.AccountId=AccountId;
        insert con;
    }
}

component:
<aura:component controller="QuickCreatecontact" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="createcontact" type="contact"/>
    <aura:attribute name="accountId" type="string"/>
   <!-- <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>-->
    <div>
        <lightning:input type="text" name="{!v.createcontact.LastName}" label="Enter LastName" />
        <lightning:input type="text" name="{!v.createcontact.FirstName}" label="Enter firstName"/>
        <lightning:input type="phone" name="{!v.createcontact.phone}" label="Enter phone"/>
        
    </div>
    <div>
        <lightning:button label="save" variant="brand" onclick="{!c.dosave}"/>
     </div>
</aura:component>

js:
({
    dosave : function(component, event, helper) {
        var action=component.get("c.createcontact");
        action.setParams({
            con:component.get("v.createcontact"),
            Id:component.get("v.accountId")
        });
        action.setCallback(this,function(response){
            var state=response.getState();
           
            if(state==='SUCCESS'){
                var result=response.getReturnValue();
               alert('SUCCESS');
                
               
            }else if(state==='INCOMPLETE'){
                
            }
        });
        $A.enqueueAction(action);
    }
})
I want to retreive value revenue from Object "B" based on input values year and servicetype fields which or common on both objects "A"  & "B" and there is no relationship between both objects, and update revenue value on Object "A"

eg: Year 2020, servicetype - gold which are common on both objects   
Hi every my scenario is to display the opportunity picklist in dropdown based on the picklist we select related records should display and if we click on update ,it should update ihave tried so far ,able to display picklist values but unable to display the records,below is the code

Apex:
public class opp1 {
    public List<SelectOption>options {set;get;}
    public List<opportunity>opportunities {set;get;}
    public List<oppwrapper>oppwraplist {set;get;}
    public string selected {set;get;}
    public opp1(){
       options=new List<SelectOption>();
        opportunities=new List<opportunity>();
        oppwraplist=new List<oppwrapper>();
        List<string>stagevalues=new List<string>{'prospecting','price/quote','need Analysis'}; 
            for(string op:stagevalues){
             SelectOption eachstage=new SelectOption(op,op);
               options.add(eachstage); 
            }
    }
    public void updatestages(){
        List<opportunity>opportunities=new List<opportunity>();
        for(oppwrapper ow:oppwraplist){
            if(ow.flag){
                ow.opp.stageName='selected';
                opportunities.add(ow.opp);
            }
        }
        
    }
    public class oppwrapper{
        public opportunity opp {set;get;}
         public boolean flag {set;get;}
    }    
    

}

vf:
<apex:page controller="opp1" >
    <apex:form >
        <apex:pageBlock >
            
      
           <apex:selectList value="{!selected}" size="1">
               <apex:selectOptions value="{!options}">
               </apex:selectOptions> 
               
            </apex:selectList>
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!opportunities}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.stageName}"/>
                <apex:column value="{!a.Amount}"/>
                
            </apex:pageBlockTable>
            </apex:pageBlockSection>
      
             <apex:pageBlockSection >
            <apex:commandButton value="update" action="{!updatestages}"/>
        </apex:pageBlockSection>
            
        </apex:pageBlock>
       
    </apex:form>
    
</apex:page>
Hi every one, In lightning is it is possible to display the toast message on the contact record page with the condition as name starts with Test.am able to display the toast message after the record is saved ,but i need to dispaly on the record page whose name starts with test.

Thanks in Advance
HEllo everyone ,
I am new to salesforce , i want to know that how can i insert parent object and its field value dynamically and then insert child objects records to it dynamically.

Note :-  i want to pass argument by which i have to pass objects and its field and records

For eg :- I have two args
Map<String, List<String>> mapOfsobject:
In this i pass parent object and list of child objects 

EX:- 'Account'=>{'Contact' ,'Opportunity'}

Map<String, Map<String, String>> mapOfsobjectField

then in this arguments i pass the field and values which i have to insert in objects 

Ex:-'Account'=>new map{'Name'=>'Test'},'Contact'=>new map{'LastName'=>'Test1'}


I have to use dynamic apex in this



I write some code but by my code i only able to insert account i am not able to insert child contact record in the account whicjh i made recently..


Here is my code:--

public class dynamicInsertFieldsRecords {  
    public static void getSobjectRecords(Map<String, List<String>> mapOfsobject ,Map<String, Map<String, String>> mapOfsobjectField ,Map<String, Integer> mapofrecord) {
        
        List<Sobject> listOfParent = new List<Sobject>();
        List<Sobject> listOfChild = new List<Sobject>();
        
        List<Sobject> sObjects = new List<Sobject>();
        List<Sobject> childsObjects = new List<Sobject>();
        
        List<Sobject> litOfsObjects = new List<Sobject>();
        
       // Map< List<Sobject>, List<Sobject>> MapParentChild = new  Map< List<Sobject>, List<Sobject>>();
        
        
        for(String sobj : mapOfsobject.keySet()){
            sObject sObj1 = Schema.getGlobalDescribe().get(sobj).newSObject() ;
            sObjects.add(sObj1);
            
            system.debug(sObjects);
        }
        
        
        for(List<String> objname1 : mapOfsobject.Values()){
            //system.debug(objname1);
            for(String str : objname1)    
            {
                sObject childsObj1 = Schema.getGlobalDescribe().get(str).newSObject() ;
                childsObjects.add(childsObj1);     
            }
        }
        
        
        String objType = String.valueOf(sObjects);
        String ChildobjType = String.valueOf(childsObjects);
        system.debug(objType);
        
        for(String str : mapOfsobjectField.Keyset()){
            system.debug(str);
            
            if(objType.contains(str)){
                //System.debug('str: ' + str);
                for(Integer i = 0; i < mapofrecord.get(str); i++){
                    //System.debug('i: ' + i);
                    sObject sObj = Schema.getGlobalDescribe().get(str).newSObject() ;
                    
                    //System.debug('sObj: ' + sObj);
                    for (String K : mapOfsobjectField.get(str).keyset()){
                        // System.debug('k  '+k);
                        sObj.put(k, (mapOfsobjectField.get(str).get(k) + i));
                        // System.debug('SObject: ' + sObj);
                    }
                    listOfParent.add(sObj);
                    System.debug('SObject: ' + sObj);
                }
                System.debug('listOfParent: ' + listOfParent);
            }  
        }
        insert listOfParent;
        // 
        Map<Id, Sobject> recordsMap = new Map<Id, Sobject>();
        recordsMap.putAll(listOfParent);
        Set<Id> recordIds = recordsMap.keySet();
        system.debug(recordIds);
        
        
        
        for(Id accId : recordIds ){
            String sObjName = accId.getSObjectType().getDescribe().getName();
             SObjectType objToken = Schema.getGlobalDescribe().get(sObjName); 
            DescribeSObjectResult objDef = objToken.getDescribe();
             Map<String, SObjectField> fields = objDef.fields.getMap();
            system.debug(sObjName);
            system.debug(objToken);
            system.debug(objDef);
            system.debug(fields);
            
            for(String str : mapOfsobjectField.Keyset()){
                system.debug(str);
                
                if(ChildobjType.contains(str)){
                    //System.debug('str: ' + str);
                    for(Integer i = 0; i < mapofrecord.get(str); i++){
                        //System.debug('i: ' + i);
                        sObject sObj = Schema.getGlobalDescribe().get(str).newSObject() ;
                        
                        //System.debug('sObj: ' + sObj);
                        for (String K : mapOfsobjectField.get(str).keyset()){
                            // System.debug('k  '+k);
                            sObj.put(k, (mapOfsobjectField.get(str).get(k) + i));
                            System.debug('SObject: ' + sObj);
                        }
                        
                        // listOfChild.add(sObjName);
                        listOfChild.add(sObj);
                        System.debug('SObject: ' + sObj);
                       // MapParentChild.put(listOfParent,listOfChild);  
                     //    System.debug('listOfParent: ' + MapParentChild);
                    }
                    System.debug('listOfParent: ' + listOfChild);
                
                    
                    
                }  
            } 
            
        }
       // insert listOfChild;
      // update MapParentChild.values();
    }
}

Can someone please help me to resolve this
 
Hi everyone, can someonehelp how to write testclass for the below class

@RestResource(urlmapping='/v1/Accountmanager/')
global class Integration_Example {
@HttpGet
    //which is used to get the records or query the records
    global static Account doget(){
        //intilaise the object
       Account a=new Account();
        //get the req parameters in map
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id');
        //query the records
        a=[select id ,name from Account where id=:accid];
        return a;
    }
    @HttpDelete
    global static Account doDelete(){
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String AccNumber = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE AccountNumber = :AccNumber ];
        delete result;
        return result;
    }
   @Httppost
    //post method is used to create the record
    global static Account docreate(string name){
        Account a = new Account(name=name);
        insert a;
        return a;
    }
     @Httpput
    global static Account doupdate(string name){
        map<string,string> paramsmap=Restcontext.request.params;
        //get the id
        string accid=paramsmap.get('Id'); 
        Account a = new Account(name=name, id=accid);
        update a;
        return a;
    }
}

Thanks in Advance
Hi everyone,the below is the class which i have written,tried testclass for that class is that crct way of writing testclass for that class.
class:
public class opp_paginationcontroller {
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public opp_paginationcontroller(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name,AccountId,Account.name,Amount,StageName,CloseDate,LastModifiedDate from Opportunity]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    // It Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Opportunity> getOpportunities() {
         return (List<Opportunity>) setCon.getRecords();
    }
}
testclass:
@isTest
public class Testopp_paginationcontroller {
@isTest
    static void invoke(){
       opportunity o=new opportunity();
        o.name='testopp';
        o.stageName='prospecting';
        o.closeDate=system.today();
        insert o;
        Test.startTest();
        opp_paginationcontroller opp=new opp_paginationcontroller();
       
        opp.refreshPageSize();
        opp.getOpportunities();
        Test.stopTest();
    }
}
Hi everyone,can someone help how to write testclass for the below code..
Thanks in Advance.

public class Displayrelatedlists {
    //1.list of wrapperclass
     public list<AccountContactWrapper> lstAccountContactWrapper { get; set; }
    public list<AccountContactWrapper> lstSelectedAccountContactWrapper { get; set; }
    //list for selecting the account records
    public list<account> selectedAccounts{get;set;} 

    public Displayrelatedlists () {
        //Allocating the memory for the list
        lstSelectedAccountContactWrapper = new list<AccountContactWrapper>();
        if(lstAccountContactWrapper == null) {
            //allocate memory for the wrapperlist
            lstAccountContactWrapper = new list<AccountContactWrapper>();
            for(account a:[select id,name,phone,(select id,name from contacts)from account limit 10]) {
                lstAccountContactWrapper.add(new AccountContactWrapper(a));
            }
        }
    }
 
    public void ProcessSelected() {
        lstSelectedAccountContactWrapper =new list<AccountContactWrapper>();
        selectedAccounts =new list<Account>();
        for(AccountContactWrapper wrapobj:lstAccountContactWrapper){
            if(wrapobj.isSelected==true) {
                selectedAccounts.add(wrapobj.acc);
            } 
        }
       
        for(Account acc:[select id,name,phone,(select id,name from contacts) from account where id in:selectedAccounts]) {
            lstSelectedAccountContactWrapper.add(new AccountContactWrapper(acc)); 
        }
             
    }
    public class AccountContactWrapper {
 
        public Account acc {get;set;}
        public boolean isSelected {get;set;}
   
        public AccountContactWrapper(account a) {
            acc = a;
            isselected=false;
        }
    }
}
Hi All, I am new to LWC.

I want to achieve, creating a Lightining Datatable which will take data and columns as input in LWC.

Will request to help in this.