• Abilash.S
  • NEWBIE
  • 40 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 32
    Questions
  • 9
    Replies
Hi Everyone
I have wrote code to create opportunity, if existing opp has 90% probability. So I have used parent-child query to queru opportunities related accounts.
I have used FOR - IN - FOR loops. The records are creating in huge number. Please provide proper code with single for loop and use handler class. I came to know that should not use tripple for loops. Then how to achieve without multiple loops.


public static void createOpp(List<Account> accList) {
        
       List<Opportunity> oppList = new List<Opportunity>();
        Map<Id, Account> acctMap = new Map<Id, Account>([Select Id, (Select Id, probability from Opportunities) from Account WHERE ID IN :accList]);
        
        for(Account a : accList) {
        
            for(Account ao: acList) {
            
                    for(Opportunity opp : ao.opportunities) {

                        if( opp.probability == 90){
                            Opportunity opptny = new Opportunity();
                            opptny.AccountId = a.Id;
                            opptny.Name      = a.Name + 'Opportunity with 90% prob new';
                            opptny.StageName = 'Prospecting';
                            opptny.probability = 90;
                            opptny.CloseDate = System.today().addMonths(3);
                            oppList.add(opptny);
                        }
                   }
               }
            }
        
        try{
        if(oppList.size() > 0){
            insert oppList;
            }
        } catch (DmlException e) {
            system.debug('Exception caused-->'+e.getMessage());
       } 
   }
Hi Everyone,

I have created apex class to pull multiple object records into single list. Where objects does not have any relationship (lets say account, contact, lead. Consider account and contact dont have any relationship). I used for loop seperately for each object and saved into wrapperlist. For threee objects I have three wrapper list. Now big challenge is I need to add three wrappers(wrapAccount, wrapContact, wrapLead)  into single list. So in that list I need all three objects records.

-------------------------------------------------------------------------
@Auraenabled(cacheable=true)  
    public static List<sObject> wrapData() {
        List<WrapperContact> wrapContact = new List<WrapperContact>();
        List<WrapperAccount> wrapAccount = new List<WrapperAccount>();
        List<WrapperLead> wrapLead = new List<WrapperLead>();
        
       
        
        for(Contact ct : [select id, name from Contact LIMIT 10]){          
            wrapContact.add(new WrapperContact(ct));            
        }
        for(Account acct : [select id, name from Account LIMIT 10]){          
            wrapAccount.add(new WrapperAccount(acct));            
        }
        for(Lead ld : [select id, name from Lead LIMIT 10]){          
            wrapLead.add(new WrapperLead(ld));            
        }
        system.debug('wrapContact'+wrapContact);
        system.debug('wrapAccount'+wrapAccount);
        system.debug('wrapLead'+wrapLead);
     List<SObject> s = new List<SObject>{
            new Contact(),
            new Account(),
            new Lead()            
        };
   //     s.add(wrapContact);
   //     s.addAll(wrapAccount);
   //         system.debug(s);
        List<sObject> objects = new List<sObject>();
    //    objects.addAll((List<sObject>)(wrapContact));
      //    objects.addAll((List<sObject>)(wrapAccount));
   //     objects.addAll(wrapLead);
          return objects;
     
    }



     public class WrapperAccount{
                
        @Auraenabled
        public Account ac{get;set;}
         
        public WrapperAccount(Account acct){
            ac=acct;
        }
        
    }

     public class WrapperContact{
        @Auraenabled
        public Contact cont{get;set;}
              
        public WrapperContact(Contact ct){
            cont=ct;
        }
                      
    }

     public class WrapperLead{
               
        @Auraenabled
        public Lead ldd{get;set;}
            
        public WrapperLead(Lead ld){
            ldd=ld;
        }
    }    

----------------------------------------------------------------------
I have used List<SObject> s = new List<SObject>{
            new Contact(),
            new Account(),
            new Lead()            
        };
   //     s.add(wrapContact);
   //     s.addAll(wrapAccount);
         s.addAll(wrapLead);
   //         system.debug(s);
But its not working. Please help me out of this.
Thanks in Advance
Hi Everyone,
We used apex class to send email to customer once case gets closed. It works fine when we use workflows to send email. But we used apex class to send email to customer. The customer has COMMUNITY license with customer profile. I dont see email related permissions for community license profiles. Is is any permission issue why customer cannot receive email. I am sure about apex class. How could I achieve this. 
Thanks in advance. 
There is an account and contact which have the relationship. In contact there is a picklist which is mandatory. Say for eg picklist contains states of India. If user selects Maharashtra state, then that user should not allow to create a record in contact. How could I accomplish this. Please provide required coding part.
I have customer feedback object. When I select picklist values of  1,2,3,4,5. Automatically stars should represent. If I select 3 from picklist, 3 stars need to display. Based on picklist values stars should display. How could I accomplish this.
Write a trigger to prevent duplicate email id in contact.
Please dont share any related links on Duplicate preventions. Help me on writing code what exactly need to apply.
Hi,

I have a requriment to create list view from VF page.

Is there any way to create listview from apex