• Vijay Nirate
  • NEWBIE
  • 60 Points
  • Member since 2016
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 7
    Replies
I would like to create a trigger to activate when using the Battle class and its battle percentage method, but it gives me a "activate percentage: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.Battle. Battle percentage: line 5, column 1 Trigger. Activate percentage: line 4, column 1 "What could be the solution? thank you
My class:
 
public class Batalla {

public List<Batalla__c> porcentajebatalla(Map<Id, Batalla__c> batallas) {
       //List<Batalla__c> ListBattle = [SELECT Id,Oponente2__c, Poder_ejercito1__c, Puntos_poder_ejercito2__c, Porcentaje_batalla__c FROM Batalla__c];
       List<Batalla__c> ListBattle = batallas.values();
       
    
       Double high = 0.0;
       Double high2 = 0.0;
       Double low = 0.0;
       Double low2 = 0.0;
       Double combatP1 = 0.0;
       Double combatP2 = 0.0;
      // Double resultBattle = 0.0;
       Double result = 0.0;
       Double result2 = 0.0;
       Integer QuerySize = ListBattle.size();
       System.debug('QuerySize = ' + QuerySize);
       if(QuerySize > 0 ) {
          for(Batalla__c battle : ListBattle){
               combatP1 = battle.Poder_ejercito1__c;
               System.debug('combatP1 = ' + combatP1);
               combatP2 = battle.Puntos_poder_ejercito2__c;
               System.debug('combatP2 = ' + combatP2);
               high = combatP1 * 0.4;
                low = combatP1  * 0.2;
               high2 = combatP2 * 0.4;
                low2 = combatP2  * 0.2;
               System.debug('high = ' + combatP1 * 0.4);
                System.debug('low = ' + combatP1  * 0.2);
               System.debug('high2 = ' + combatP2 * 0.4);
                 System.debug('low2 = ' + combatP2  * 0.2);
               result = (math.random() * (high-low) + low);
              result2 = (math.random() * (high2-low2) + low2);
               battle.Porcentaje_batalla__c = result;
              battle.Porcentaje_2__c = result2;
               /*System.debug('battle.Porcentaje_batalla__c = ' + battle.Porcentaje_batalla__c);
                resultBattle = combatP2 - result;
               System.debug('resultBattle = ' + resultBattle);*/
                System.debug('result = ' + result);
              System.debug('result2 = ' + result2);
           }
       }
         upsert ListBattle;
       return ListBattle;
   }  


}

And my trigger is:
 
trigger activarporcentaje on Batalla__c (before insert) {
	
   Batalla bata = new Batalla();
   bata.porcentajebatalla(Trigger.newMap);
    
}

 
  • October 10, 2019
  • Like
  • 0

 Let’s say you want to process 1 million records using Batch Apex.

batch size is 200

a.)then how many batch are created.

b.) how many transaction are created.

c.) how many times batch are call

d.) how many times finish execute method are executed.

 

Apex class:
public class Auraopportunity {

    
    @AuraEnabled
    public static list<opportunity> getdata(){
        
      list<opportunity>lstopp =[select id, name, type, amount from opportunity limit 5];   
       return lstopp; 
    }
}

 Component:
<aura:component controller="Auraopportunity">
    <aura:attribute name ="opportunities" type="list"/>
    
    <aura:iteration items="{!v.opportunities}" var="a">
   
   <h1>{!a.id}</h1>
    </aura:iteration>
    
    <aura:handler name="init" value="{!this}" action="{!c.show}"/>
</aura:component>
Controller
({
	show : function(component, event, helper) {
		alert("Hello");
        
        var abc= component.get("c.getdata");
         console.log("Method is invoked");
        abc.setCallback(this,function(response){
             
          var state = response.getState();
             console.log(state);
            
            if(state === "SUCCESS"){
                
                var result = response.getReturnValue();
                console.log(result);
                alert(result);
                component.set("!v.opportunities",  result);
            }else{
                
                 console.log("Failed");
            }
        });
        $A.enqueueAction(abc);
        
	}
})

iam calling in the application :
 
<aura:application >
    <c:Auraoppiteration/>	
</aura:application>
it is not getting display, may i know  , im getting the timeout error itseems, ..
Thanks
Deepika
Hi All,

I am using SOAP API to access to community, but error occured with [LoginFault [ApiFault  exceptionCode='INVALID_LOGIN'
 exceptionMessage='Invalid username, password, security token; or user locked out.'
 extendedErrorDetails='{[0]}'
I think ending point or something is wrong, please provide infos,
and also i will post my code. 
    static final String USERNAME = "son@gmail.co.kr";
    static final String PASSWORD = "a1s2d3f4";
    static PartnerConnection connection;

    public static void main(String[] args) {
        ConnectorConfig config = new ConnectorConfig();
        config.setUsername(USERNAME);
        config.setPassword(PASSWORD);

        config.setAuthEndpoint(
                "https://clvs-developer-edition.ap15.force.com/customersupport/services/Soap/u/47.0/00D2v000001ddCh");

        // config.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/47.0");

        try {
            connection = new PartnerConnection(config);
            System.out.println(connection);
            System.out.println("Auth EndPoint:" + config.getAuthEndpoint());
            System.out.println("Service EndPoint:" + config.getServiceEndpoint());
            System.out.println("Username: " + config.getUsername());
            System.out.println("SessionId: " + config.getSessionId()); 
I would like to create a trigger to activate when using the Battle class and its battle percentage method, but it gives me a "activate percentage: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.Battle. Battle percentage: line 5, column 1 Trigger. Activate percentage: line 4, column 1 "What could be the solution? thank you
My class:
 
public class Batalla {

public List<Batalla__c> porcentajebatalla(Map<Id, Batalla__c> batallas) {
       //List<Batalla__c> ListBattle = [SELECT Id,Oponente2__c, Poder_ejercito1__c, Puntos_poder_ejercito2__c, Porcentaje_batalla__c FROM Batalla__c];
       List<Batalla__c> ListBattle = batallas.values();
       
    
       Double high = 0.0;
       Double high2 = 0.0;
       Double low = 0.0;
       Double low2 = 0.0;
       Double combatP1 = 0.0;
       Double combatP2 = 0.0;
      // Double resultBattle = 0.0;
       Double result = 0.0;
       Double result2 = 0.0;
       Integer QuerySize = ListBattle.size();
       System.debug('QuerySize = ' + QuerySize);
       if(QuerySize > 0 ) {
          for(Batalla__c battle : ListBattle){
               combatP1 = battle.Poder_ejercito1__c;
               System.debug('combatP1 = ' + combatP1);
               combatP2 = battle.Puntos_poder_ejercito2__c;
               System.debug('combatP2 = ' + combatP2);
               high = combatP1 * 0.4;
                low = combatP1  * 0.2;
               high2 = combatP2 * 0.4;
                low2 = combatP2  * 0.2;
               System.debug('high = ' + combatP1 * 0.4);
                System.debug('low = ' + combatP1  * 0.2);
               System.debug('high2 = ' + combatP2 * 0.4);
                 System.debug('low2 = ' + combatP2  * 0.2);
               result = (math.random() * (high-low) + low);
              result2 = (math.random() * (high2-low2) + low2);
               battle.Porcentaje_batalla__c = result;
              battle.Porcentaje_2__c = result2;
               /*System.debug('battle.Porcentaje_batalla__c = ' + battle.Porcentaje_batalla__c);
                resultBattle = combatP2 - result;
               System.debug('resultBattle = ' + resultBattle);*/
                System.debug('result = ' + result);
              System.debug('result2 = ' + result2);
           }
       }
         upsert ListBattle;
       return ListBattle;
   }  


}

And my trigger is:
 
trigger activarporcentaje on Batalla__c (before insert) {
	
   Batalla bata = new Batalla();
   bata.porcentajebatalla(Trigger.newMap);
    
}

 
  • October 10, 2019
  • Like
  • 0
Im using ui:inputDate  to display date filed ,
Is there any solution to disable the past dates in date picker?
Hello Guys

i am new to the trigges and apex development, so here  is my requirement - There is checkbox Called "Private__c" in account object
Once locked, if a new Lead is created with this Private Locked Account which already has a Allocated Owner, then a new Contact should be created for this Account under the allocated Account owner name. Lead will not be created. 

And If a new lead is added without a Private Account checkbox being checked then allow the Lead to be created with Lead creator as the Lead owner. 

so far i have tried to design a trigger, but its not meeting up my goal
 
trigger AutoConvertLeadAccount on Lead (after insert) {
    Set<String> leademails = new Set<String>();
    List<Lead> newLeads = new List<Lead>();

    // Get all the new leads
    for(Lead l : system.trigger.new){
        newLeads.add(l);
        leademails.add(l.email);
    }

    /* Make some maps of account and email addresses */
    List<Account> AccountList = [select Id, Website, OwnerId from Account where Website IN: leademails];
    Map<ID, String> peAccounts = new Map<ID, String>();
    Map<ID, ID> peAccountsOwner = new Map<ID, ID>();

if(AccountList.size()>0){
    // Generic map for preventing loss of ids
    for(Account a : AccountList){
        peAccounts.put(a.id, a.Website);
        peAccountsOwner.put(a.id, a.OwnerId);
    }

    // We will need this to get the id from the email address
    Map<String, ID> peAccountsFlipped = new Map<String, ID>();
    for(ID i : peAccounts.keyset()){
        peAccountsFlipped.put(peAccounts.get(i), i);
    }

    /* System Conversion Requirements */
    leadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
    Database.LeadConvert lc = new Database.LeadConvert();

    /* Configuring Payload */    
    for (Lead nl : newleads) {
        lc = new Database.LeadConvert();
        lc.setLeadId(nl.id);
        lc.setOverwriteLeadSource(false);
        lc.setConvertedStatus(convertStatus.MasterLabel);

        // Check to see if account already exists
        if(!peAccounts.isEmpty()){
            if(peAccountsFlipped.get(nl.email)!=null){
                lc.setAccountId(peAccountsFlipped.get(nl.email));
                lc.setOwnerId(peAccountsOwner.get(peAccountsFlipped.get(nl.email)));
                lc.setDoNotCreateOpportunity(true);
            }    
        } else {
            // In the event an account doesn't exist
            lc.setOwnerId(nl.OwnerId);
            lc.setDoNotCreateOpportunity(false);
            lc.setOpportunityName(nl.Name);
        }
        leadConverts.add(lc);
    }

    // Fire Payload
    Database.LeadConvertResult[] lcr = Database.convertLead(leadConverts);
    System.debug(LoggingLevel.INFO, lcr);
 }
}