• Neha Arora 50
  • NEWBIE
  • 25 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hello Ohana,

I am getting an error 'Variable does not exist: varName' when I tried to access my global variable in the finish method of the batch class.
Point to Note:
1. Neither I am using a stateful class, not any static variable. So in any case values will be retained in my variable.
2. According to the salesforce article global variables declared in the batch class are accessible in all 3 methods.
Steps already performed:
1. The variable is initiated in the constructor with the parameter passed to the batch class.
2. The same variable is used in the start method to build my query.
Issues:
When I tries to access in finish method got an error saying the variable does not exist.
Below is the code snippet:

global class clsName implements DataBase.Batchable{
  global string var;
  public void clsName(string param){
     this.var = param;
  }
  public Database.queryLocator start(....){
       return Databse.getQueryLocator('SELECT Id from Account where ID =: 'var');
  }
  public static void execute(....){
     //Some Logic
  }
  public static void finish(....){
     System.debug(var);   //Error variable does not exist: var
  }
}

Let me know your suggestion or if I am making any mistake.
Thanks in advance.

HI,

I have created a workflow rule, in which a task should be created for all the users who are in CEO role. There are two 2 users under this role and task should be assigned to both the users.

Based on the specified criteria when I create a record, workflow rule is triggerd and but task is created for the user who have created that record i.e., Assigned To Id (Task) = Creted By (Main Object from which workflow rule is triggered).

I have tried to implement the same approach with the process builder too, and assigned the Role ID to the Assigned to Id field of task but it gives me an error and does not let me to sve the record. 

This is the error I was getting - 
We can't save this record because the “Record Name” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: MALFORMED_ID: Assigned To ID: id value of incorrect type: 2F00Ec00000011UtU. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 296214298-72703 (1978889399)ook up ExceptionCode values in the SOAP API Developer Guide. Error ID: 296214298-72703 (1978889399)

I have created the XML and object file to create CUSTOM OBJECT and it's fields, deployed through workbench, it was deployed successfully but object was not created in the org and so its fields. I have tried 2 approaches for creating that
1. specified the object and field information in object file and deployed 
2. created the object into the org and only deploy its fields
in both cases zip file was deployed successfully, but in 1st case object was not created and in 2nd case fields were not created
It will be very helpful if someone can specify the sample object file to create custom object and its fields.
I am attaching the screenshot of successful deployment, XML File and object file.

User-added image

User-added image
User-added image
Please let me know if I have made any mistake.

I have also tried to create them through spreadsheet, mapped all the field's data type but neither I could not specify the required attribute for the fields, nor add more than 10 fields on the layout. Also it was failed to store picklist values.
Any help would be appricated.
Thank you.

Hi, I am new to development and and stuck with two different scenario for a trigger on before insert & before update context variables.

SCENARIO 1 - BEFORE INSERT

I have created 2 objects, 1 is for Course and another is Student.
Trigger is on the student object which will check the open vacancies(formula field on course i.e. Total strength - Total no of students(which is again a roll up summary of count of students)) for the course he/she will apply for.
If the open vacancy == 0 then the admin should get error while creating record. 

set<Id> courseIds = new set<Id>();
            System.debug('Before insert trigger fired');
            for(Student__c student : Trigger.New){
                courseIds.add(student.Course_Name__c);
            }
            for(Course__c course : [SELECT Id, Name, Open_Vacancies__c FROM Course__c WHERE Id IN: courseIds]){
                if(course.Open_Vacancies__c == 0){
                    System.debug('Seats are full');
                }
            }


Please refer the above code snippet I have wrote but the problem is I can not add addError() method on the student record as it is out of for loop. Debug is working fine but also create the record. SInce it is creating record open vacacy is field's value is going in negative but it should not happen until and unless open vacancy > 0.

SCENARIO 2 - BEFORE UPDATE

For this scenario also facing same issue wih addError() method. Here the scenario is to restrict the admin from updating the enrollment no.(field on student object). If the enrollment no is updating then it should give an error message

if(Trigger.isUpdate){
            for(Student__c student : Trigger.old){
                System.debug('Before Update trigger fired');
                if(Trigger.oldMap.get(student.Id).Enrollment_Number__c != Trigger.NewMap.get(student.Id).Enrollment_Number__c){
                    System.debug('You can not update the enrollment number');
                    
                    //One way to show error
                    student.addError('You can not update enrollment number');
                    
                    //Another way to show error
                    Student__c record = Trigger.oldMap.get(student.ID);
                    record.addError('You can not update enrollment number');
                }
            } 
        }


Please refer the above code snippet I have wrote here also, debug is working fine, but addError Method is not working.

Thanks.

Hi, I am trying to delete portal account into my test class, so that user related to that account should automatically get remove from the collaborationGroup.
I have tried to set the user IsActive to false, still unable to delete to that account, and giving me an error --

System.DmlException: Delete failed. First exception on row 0 with id 0036C00000SLUidQAH; first error: DELETE_FAILED, Your attempt to delete rtkek could not be completed because it is associated with the following portal users.: yourusername05112020@gmail.com
: []


This is how I am trying to delete account and to disable user..

List<User> userToDelete = new List<User>([SELECT Name, IsActive FROM User WHERE UserName = 'yourusername05112020@gmail.com']); 
            userToDelete[0].IsActive = false;
            update userToDelete;
            
            List<Contact> contactToDelete = new List<Contact>([SELECT LastName FROM Contact WHERE LastName = 'test']); 
            delete contactToDelete;
            
            List<Account> advisorToDelete = new List<Account>([SELECT Name FROM Account WHERE Name = 'Test Advisor 2']); 
            delete advisorToDelete;
I have a trigger that I have created a test for, this gives me 100% coverage for the trigger but the test has an error System.AssertException: Assertion Failed
This is the trigger:
trigger AddUUID on Advertisement__c (before insert) {
    
    Uuid myUuid = new Uuid();
String myUuidValue = myUuid.getValue();
    
    for(Advertisement__c  acc:trigger.new){acc.UUID__c = myUuidValue;}

}

This is the test class:
@istest
public class TestAdvertisementUUID {
    @istest
    public static void testadvertisement(){
       Advertisement__c ADV = new Advertisement__c(Apprenticeship_Opportunity__c='0064L000009nWLaQAM');
        test.startTest();
        Database.SaveResult result = Database.insert(ADV,False);
        Test.stopTest();
        System.assert(!result.isSuccess());
    }
}

Any help as to what I'm doing wrong would be greatly appreciated
I have a batch apex job that builds a select statement for contact records for the start method.  When I am in the execute method, I loop through the account records and for each one, I have a select to go get something from a custom object for locations.  An account can have more than one location.

In the execute method the job fails because of that select within the for loop of accounts.  Too many account, to many loops with a select in it.

I'm thinking the original select in the start method should be modified to select the account and the locations.  But how do I do that?  I want the execute method to be handed a list of accounts with each one having a list of locations.

Does anyone know how to pass a list to the execute method where each record has one or more items in a list from another object?
 
public without sharing class X311Portal_EditProfileCtrl {
    @AuraEnabled
    public static Map<String, Object> getContactDetails(){
        
        Map<String, Object> returnMap = new Map<String, Object>();
        
        User userRecord = [SELECT Id, AccountId, ContactId FROM User WHERE Id =: UserInfo.getUserId()];
        
        Account personAccRecord = [SELECT FirstName, LastName, PersonEmail, Phone, PersonMailingCity, PersonMailingState,
                                    PersonMailingPostalCode, PersonMailingStreet FROM Account WHERE Id =: userRecord.AccountId];
        
        returnMap.put('personAccRecord', personAccRecord);
        
        return returnMap; 
    }   

    @AuraEnabled
    public static void updateContactDetails(String record) {
        Account accountRecord = (Account) JSON.deserialize(record, Account.class);
        upsert accountRecord;
    }
}
Hello Ohana,

I am getting an error 'Variable does not exist: varName' when I tried to access my global variable in the finish method of the batch class.
Point to Note:
1. Neither I am using a stateful class, not any static variable. So in any case values will be retained in my variable.
2. According to the salesforce article global variables declared in the batch class are accessible in all 3 methods.
Steps already performed:
1. The variable is initiated in the constructor with the parameter passed to the batch class.
2. The same variable is used in the start method to build my query.
Issues:
When I tries to access in finish method got an error saying the variable does not exist.
Below is the code snippet:

global class clsName implements DataBase.Batchable{
  global string var;
  public void clsName(string param){
     this.var = param;
  }
  public Database.queryLocator start(....){
       return Databse.getQueryLocator('SELECT Id from Account where ID =: 'var');
  }
  public static void execute(....){
     //Some Logic
  }
  public static void finish(....){
     System.debug(var);   //Error variable does not exist: var
  }
}

Let me know your suggestion or if I am making any mistake.
Thanks in advance.

HI,

I have created a workflow rule, in which a task should be created for all the users who are in CEO role. There are two 2 users under this role and task should be assigned to both the users.

Based on the specified criteria when I create a record, workflow rule is triggerd and but task is created for the user who have created that record i.e., Assigned To Id (Task) = Creted By (Main Object from which workflow rule is triggered).

I have tried to implement the same approach with the process builder too, and assigned the Role ID to the Assigned to Id field of task but it gives me an error and does not let me to sve the record. 

This is the error I was getting - 
We can't save this record because the “Record Name” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: MALFORMED_ID: Assigned To ID: id value of incorrect type: 2F00Ec00000011UtU. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 296214298-72703 (1978889399)ook up ExceptionCode values in the SOAP API Developer Guide. Error ID: 296214298-72703 (1978889399)

Hi, I am new to development and and stuck with two different scenario for a trigger on before insert & before update context variables.

SCENARIO 1 - BEFORE INSERT

I have created 2 objects, 1 is for Course and another is Student.
Trigger is on the student object which will check the open vacancies(formula field on course i.e. Total strength - Total no of students(which is again a roll up summary of count of students)) for the course he/she will apply for.
If the open vacancy == 0 then the admin should get error while creating record. 

set<Id> courseIds = new set<Id>();
            System.debug('Before insert trigger fired');
            for(Student__c student : Trigger.New){
                courseIds.add(student.Course_Name__c);
            }
            for(Course__c course : [SELECT Id, Name, Open_Vacancies__c FROM Course__c WHERE Id IN: courseIds]){
                if(course.Open_Vacancies__c == 0){
                    System.debug('Seats are full');
                }
            }


Please refer the above code snippet I have wrote but the problem is I can not add addError() method on the student record as it is out of for loop. Debug is working fine but also create the record. SInce it is creating record open vacacy is field's value is going in negative but it should not happen until and unless open vacancy > 0.

SCENARIO 2 - BEFORE UPDATE

For this scenario also facing same issue wih addError() method. Here the scenario is to restrict the admin from updating the enrollment no.(field on student object). If the enrollment no is updating then it should give an error message

if(Trigger.isUpdate){
            for(Student__c student : Trigger.old){
                System.debug('Before Update trigger fired');
                if(Trigger.oldMap.get(student.Id).Enrollment_Number__c != Trigger.NewMap.get(student.Id).Enrollment_Number__c){
                    System.debug('You can not update the enrollment number');
                    
                    //One way to show error
                    student.addError('You can not update enrollment number');
                    
                    //Another way to show error
                    Student__c record = Trigger.oldMap.get(student.ID);
                    record.addError('You can not update enrollment number');
                }
            } 
        }


Please refer the above code snippet I have wrote here also, debug is working fine, but addError Method is not working.

Thanks.

Hi, I am trying to delete portal account into my test class, so that user related to that account should automatically get remove from the collaborationGroup.
I have tried to set the user IsActive to false, still unable to delete to that account, and giving me an error --

System.DmlException: Delete failed. First exception on row 0 with id 0036C00000SLUidQAH; first error: DELETE_FAILED, Your attempt to delete rtkek could not be completed because it is associated with the following portal users.: yourusername05112020@gmail.com
: []


This is how I am trying to delete account and to disable user..

List<User> userToDelete = new List<User>([SELECT Name, IsActive FROM User WHERE UserName = 'yourusername05112020@gmail.com']); 
            userToDelete[0].IsActive = false;
            update userToDelete;
            
            List<Contact> contactToDelete = new List<Contact>([SELECT LastName FROM Contact WHERE LastName = 'test']); 
            delete contactToDelete;
            
            List<Account> advisorToDelete = new List<Account>([SELECT Name FROM Account WHERE Name = 'Test Advisor 2']); 
            delete advisorToDelete;
I'm new to developing in Salesforce and am working on the Define Custom Big Objects unit in Trailhead.  I understand that I'm supposed to make Rider_History__b.object file as well as a rider_history.permissionset and package.xml file.  However, I don't know how to actually begin the process on how to get these files created.

I understand that once it's created I can then use the Workbench to upload the zip file into my trailhead environment, but I can't do that until after the files have actually been created.  How do I do that????  Is it done in an Apex class? Or is it done as a different type of item in the Developer Console? Or is it done a completely different way.

Remember, I'm a newb when it comes to this stuff, so you may need to be a bit more specific than with a more experienced developer.