• Peter Guzman Garcia 22
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi;
I am hoping to get some help on this trigger. I am new to Apex programming. I have a custom object called Dues Calculator. For which I have a picklist depency, when the user selects one option "Unit Type" two additional picklist fields that need to be filled out are pre-populated with the correct options. Since I need to use those fields in formula. I created addtional fields that end in "selected". The purpose of my trigger is to automatically populate the "selected" fields with the options from the picklist depencies.
This is my trigger:
trigger NumberofUnitsPerTypeSelected on Dues_Calculator__c (before insert) {
    for(Dues_Calculator__c dues : Trigger.New){
        
       // Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
        Decimal numberUnitTypeSelected   = Dues.Number_of_Units_Per_Type_Selected__c;
        String  numberUnitType           = Dues.Number__c;
        numberUnitType                     = numberUnitTypeSelected.format(); 
            
        // Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
        Decimal percentageSelected       = Dues.Percentage_of_Ownership_Type_Selected__c;
        String  percentageOwnershipShare = Dues.Percentage_of_Ownership_Share__c;
        percentageOwnershipShare         = percentageSelected.format();
        
        insert dues;
        }
}

I get a Null Pointer Exception error, I tried to add the option to create a list. I am stuck here.

Any help is greatly appreciated;
Peter
Hi;
I am hoping to get some help on this trigger. I am new to Apex programming. I have a custom object called Dues Calculator. For which I have a picklist depency, when the user selects one option "Unit Type" two additional picklist fields that need to be filled out are pre-populated with the correct options. Since I need to use those fields in formula. I created addtional fields that end in "selected". The purpose of my trigger is to automatically populate the "selected" fields with the options from the picklist depencies.
This is my trigger:
trigger NumberofUnitsPerTypeSelected on Dues_Calculator__c (before insert) {
    for(Dues_Calculator__c dues : Trigger.New){
        
       // Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
        Decimal numberUnitTypeSelected   = Dues.Number_of_Units_Per_Type_Selected__c;
        String  numberUnitType           = Dues.Number__c;
        numberUnitType                     = numberUnitTypeSelected.format(); 
            
        // Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
        Decimal percentageSelected       = Dues.Percentage_of_Ownership_Type_Selected__c;
        String  percentageOwnershipShare = Dues.Percentage_of_Ownership_Share__c;
        percentageOwnershipShare         = percentageSelected.format();
        
        insert dues;
        }
}

I get a Null Pointer Exception error, I tried to add the option to create a list. I am stuck here.

Any help is greatly appreciated;
Peter
Hi;
I am hoping to get some help on this trigger. I am new to Apex programming. I have a custom object called Dues Calculator. For which I have a picklist depency, when the user selects one option "Unit Type" two additional picklist fields that need to be filled out are pre-populated with the correct options. Since I need to use those fields in formula. I created addtional fields that end in "selected". The purpose of my trigger is to automatically populate the "selected" fields with the options from the picklist depencies.
This is my trigger:
trigger NumberofUnitsPerTypeSelected on Dues_Calculator__c (before insert) {
    for(Dues_Calculator__c dues : Trigger.New){
        
       // Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
        Decimal numberUnitTypeSelected   = Dues.Number_of_Units_Per_Type_Selected__c;
        String  numberUnitType           = Dues.Number__c;
        numberUnitType                     = numberUnitTypeSelected.format(); 
            
        // Converting and Assigning the Picklist Value to the Selected Field to be used in a formula
        Decimal percentageSelected       = Dues.Percentage_of_Ownership_Type_Selected__c;
        String  percentageOwnershipShare = Dues.Percentage_of_Ownership_Share__c;
        percentageOwnershipShare         = percentageSelected.format();
        
        insert dues;
        }
}

I get a Null Pointer Exception error, I tried to add the option to create a list. I am stuck here.

Any help is greatly appreciated;
Peter
Hi All,

This is My Code  
I need to access glist Type(id) in My postopptoslack() Method.
That's why I have made glist as Public But when I am Accessing glist In  My2() method it's showing value of Id.
But When I am try to accessing this glist variable in postopptoslack() method then it's Showing the value as Null. What Can I do to access this value in the method?.




public with sharing class PostToSlack {
   public static id glist;
@invocableMethod(label='post win opp to slack'
                description='posting deatils of opportunity'
                category='opportunity')
    public static void postopp(list<id> opp){
        system.debug('flow');
       system.debug('op'+opp[0]);     
        system.debug('oppid'+opp);
        PostToSlack.my2(opp[0]);
    }
   
    public static id my2(id gl){
            glist=gl;
        system.debug('methodlist'+glist+' '+gl);
        return gl;
    }
     static{
        system.debug('static'+glist);
    }
    @auraenabled(cacheable=true)
    public static void getlist(list<string> values1){
        PostToSlack.postopptoslack(values1);
    }
    public static void postopptoslack(list<string> values2){
        system.debug('this'+glist);
        string sn='';
         Date cd;
         decimal a;
         string n='';
        //string a='name';
        system.debug('opp'+values2);
        string q1='select ';
        for(integer i=0;i<values2.size();i++){
            q1+=values2[i]+',';
        }
        system.debug('g'+glist);
        q1+='id,Link__c from opportunity where id =:glist';
        
        list<opportunity> oplist=database.query(q1);
        system.debug('oplist'+oplist);

        if(!oplist.isEmpty()){
            string mssg='';
           
            for(opportunity op:oplist){
                
                for(integer i=0;i<values2.size();i++){
                   
                    String var =values2[i];
                    if(var=='stagename')
                    {
                        sn=op.StageName;  
                        mssg+='StageName ='+' '+sn+'\n';
                    }
                    else if(var=='amount'){
                        a=op.Amount;
                        mssg+='Amount ='+' '+a+'\n';
                    }
                    else if(var=='closeDate'){
                        cd=op.CloseDate;
                        mssg+='CloseDate ='+' '+cd+'\n';
                    }
                    else if(var=='name'){
                        n=op.Name;
                        mssg+='Name ='+' '+n+'\n';
                    }
                
               
                }
          
                }
            system.debug('message'+mssg);
            Http http=new Http();
            HttpRequest req=new HttpRequest();            
            req.setEndpoint('https://hooks.slack.com/services/xKdM9Mk29hFhhUcH2Khbkydf');
            req.setMethod('POST');
            req.setHeader('content-Type', 'application/json;charset=UTF-8');
            req.setBody('{"text":"'+ mssg+ '"}');
            
            try{
            HttpResponse response=http.send(req);
                if(response.getStatusCode()==200){
                    system.debug('success');
                }
                else{
                    system.debug('Error');
                }
            }
            catch(exception e){
                system.debug('Error'+e.getMessage());
            }
        }
    }
}