• Shanu Kumar 18
  • NEWBIE
  • 35 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Hi, I am learning SF developer. I created 100 records in Account object using SQL query. then im trying to delete all those records using SOQL query and for loop here is my code:
list<Account> newlist=new list<Account>();
newlist=[SELECT Id,Name FROM Account WHERE Name='test name'];
system.debug('list'+newlist);
list<Account> deletelist=new list<Account>();
for(Account a: newlist){
    a.Name='test name';
    deletelist.add(a);
}
system.debug('list'+deletelist);
delete deletelist;
but i am unable to delete. i know i can use work bench for this but i want to delete using SOQL here is the error im facing:
Line: 10, Column: 1
System.DmlException: Delete failed. First exception on row 0 with id 0016F00003O5AOEQA3; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, acountdeletetrigger: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object Class.accountdeleteclass.deletecheck: line 3, column 1 Trigger.acountdeletetrigger: line 3, column 1: []
please tell me whats wrong thanks
Hi,

I am executing Batch Apex this type of error showing can you please solve my problem
(Line: 2, Column: 10
Method does not exist or incorrect signature: void executeBatch(BatchApexExample) from the type Database.
this is my code:

global class BatchApexExample implements DataBase.Batchable<sObject>
{
    global String query = 'oppartunaty';
  global DataBase.QueryLocator start(DataBase.BatchableContext bc)
    {
        
        string query='select id,name,amount, Discription from oppartunaty';
        return Database.getQueryLocator(query);
    }
        
     global void execute(DataBase.BatchableContext bc, List<oppartunaty> records){
    
        
        for(oppartunaty  opp: records)
        {
            opp.amount=2000;
            opp.Discription='this my first batch Apex';
                
        }
         update records;
       
        // process each 
    }
    global void finish(Database.BatchableContext bc){
        //procee    
    }
     
}
Hi, I am learning SF developer. I created 100 records in Account object using SQL query. then im trying to delete all those records using SOQL query and for loop here is my code:
list<Account> newlist=new list<Account>();
newlist=[SELECT Id,Name FROM Account WHERE Name='test name'];
system.debug('list'+newlist);
list<Account> deletelist=new list<Account>();
for(Account a: newlist){
    a.Name='test name';
    deletelist.add(a);
}
system.debug('list'+deletelist);
delete deletelist;
but i am unable to delete. i know i can use work bench for this but i want to delete using SOQL here is the error im facing:
Line: 10, Column: 1
System.DmlException: Delete failed. First exception on row 0 with id 0016F00003O5AOEQA3; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, acountdeletetrigger: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object Class.accountdeleteclass.deletecheck: line 3, column 1 Trigger.acountdeletetrigger: line 3, column 1: []
please tell me whats wrong thanks
I'm doing the "Test Apex Triggers" challenge and get this error:
"The 'RestrictContactByName' class did not achieve 100% code coverage via your test methods"

I also attach my code here, can you show me where could it be the wrong spot?
 
@isTest
public class TestRestrictContactByName {
    @isTest static void TestInsertContact_INVALIDNAME(){
		Contact contact = new Contact(LastName='INVALIDNAME');
        Test.startTest();
        Database.SaveResult result = Database.insert(contact);
        Test.stopTest();
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name "'+contact.LastName+'" is not allowed for DML',
                             result.getErrors()[0].getMessage());
    }
    
    @isTest static void TestInsertContact_VALIDNAME(){
		Contact contact = new Contact(LastName='VALIDNAME');
        Test.startTest();
        Database.SaveResult result = Database.insert(contact);
        Test.stopTest();
        System.assert(result.isSuccess());
    }
    
    @isTest(SeeAllData=true) static void TestUpdateContact_INVALIDNAME(){
		Contact contact = [SELECT Id FROM Contact WHERE LastName = 'Test Contact' LIMIT 1];
        contact.LastName = 'INVALIDNAME';
        Test.startTest();
        Database.SaveResult result = Database.update(contact);
        Test.stopTest();
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name "'+contact.LastName+'" is not allowed for DML',
                             result.getErrors()[0].getMessage());
    }
    
    @isTest(SeeAllData=true) static void TestUpdateContact_VALIDNAME(){
		Contact contact = [SELECT Id FROM Contact WHERE LastName = 'Test Contact' LIMIT 1];
        contact.LastName = 'VALIDNAME';
        Test.startTest();
        Database.SaveResult result = Database.update(contact);
        Test.stopTest();
        System.assert(result.isSuccess());
    }
}

 
I have Standard Object and Custom Object 
Standard Object fields are Id, LastactivityDate. Object name is Leads
Custom Object fields are Id, Lead__c. Object Name Email_Lead_Sync__c
I need LastActivity < Last_N_Days:90   Soql Query can any one help me.
Hi,
I have to simply call a lightning component from a VisualForce Page. Later this VF page is configured as a list button in Opportunity.
VF Page::
<apex:page standardController="Opportunity" recordSetVar="opp"  tabStyle="Opportunity"> 
<apex:includeLightning />
 <script>
    //    var recordid = "{!$CurrentPage.parameters.id}";    
         $Lightning.use("c:LightningOutContainerApp", function() {
         $Lightning.createComponent("c:RelatedListNewRecordPOC",
         { 
         oppRecordId : "0069000000x6KWSAA2" 
         },
         "RelatedListNewRecordPOCContainer",
         function(cmp) {
         console.log('Component created, do something cool here');
         });
         });
 </script>
</apex:page>
Lightning App:
<aura:application access="GLOBAL" extends="ltng:outApp">
 	<aura:dependency resource="c:RelatedListNewRecordPOC"/>	
</aura:application>

Component:
<aura:component controller="RelatedListNewRecordPOCController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="oppRecordId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>

JS Controller:
({

    doInit: function(component, event, helper) {
        var myRecordId = "0069000000x6KWSAA2";//component.get("v.recordId");
        var getParameters = component.get('c.getParameters');
        getParameters.setParams({
            "myRecordId": myRecordId
        });

        getParameters.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var Opportunity = response.getReturnValue();               
                var createAcountContactEvent = $A.get("e.force:createRecord");
                createAcountContactEvent.setParams({
                    "entityApiName": "Opportunity",
                    "RecordTypeId": Opportunity.RecordTypeId,
                    "defaultFieldValues": {
                        'AccountId': Opportunity.AccountId,
                        'Name': Opportunity.Name,
                        'StageName':Opportunity.StageName,
                        'CloseDate':Opportunity.CloseDate
                    }
                });
                createAcountContactEvent.fire();

            } else {
                var closeAction = $A.get("e.force:closeQuickAction");
                closeAction.fire();
            }
        });
        $A.enqueueAction(getParameters);
        $A.get("e.force:closeQuickAction").fire();
    },
})

Apex Controller:
public class RelatedListNewRecordPOCController {
    
    @AuraEnabled
    public static Opportunity getParameters(Id myRecordId){
        return [SELECT Id, AccountId, RecordTypeId, Name, Description, StageName, Amount
                , TotalOpportunityQuantity, CloseDate, Type, LeadSource, IsClosed FROM Opportunity WHERE Id =: myRecordId ];    }
	
}
Here I'm getting an error while calling the getParameters() function from LC only when from VF page which is configured in list button.
If I run the LC from actions, it is working.
Error:  $A.getCallback() [Unable to get property 'setParams' of undefined or null reference] Callback failed: apex://RelatedListNewRecordPOCController/ACTION$getParameters
Can anyone please help. As per requirement I have to configure it in list button and I'm not able to dibug this.