• Lam Ha Tuan
  • NEWBIE
  • 20 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 3
    Replies

Hello everyone! I am new to Apex coding.
I am trying to create an Apex class to create some default records for my custom Object. Here is my PostInstall class:
global without sharing class PostInstall implements InstallHandler {
global void onInstall(InstallContext context) {
Account a = new Account(Name = 'Hello');
insert a;
}
}
I create a unit test for it: 

public class UnitTestClass {
    @isTest
    static void testInstallScript() {
      PostInstall postinstall = new PostInstall();
        Test.testInstall(postinstall, null);
        Test.testInstall(postinstall, new Version(0,1,0), true);
        Account[] a = [select id from Account where Name = 'Hello'];
        System.assertEquals(a.size(), 1, 'Hehe');
      }
}

And the UnitTestClass is correct. But when I try to create a package and install it to another org, the PostInstall class isn't even called to create records for Account object. Can you help me with this problem? Thank you so much.

Hi guys, I am new to Apex so that I am not sure about how the upsert work. I have the apex class to create an project, add members (are the users in the org) from teams and add users from the org to project. Users and Members from teams can be duplicate so I use 'upsert' to make sure I just add user to project member 1 time. Here is my Apex method:

insert project;
        for(String team: teams){
            Project_Team__c newProjectTeam = new Project_Team__c(Project__c = project.Id, Team__c = team);
            insert newProjectTeam;
            for(Team_Member__c teamMember: [Select Member__c from Team_Member__c where Team__c = :team]){
                Project_Member__c newProjectMember = new Project_Member__c(Project__c = project.Id, Member__c = teamMember.Member__c);
                upsert newProjectMember;
                System.Debug(newProjectMember);
            }
        }
        for(String member: members){
            Project_Member__c newProjectMember = new Project_Member__c(Project__c = project.Id, Member__c = member);
            upsert newProjectMember;
            System.Debug(newProjectMember);
        }

Is my code correct, especially the 'upsert' DMl?

Hi guys, are there any way that when user install my app to their org, it will automatically insert some default record for that org? I also have an object to store personal settings for user, how can I create record for each user when they install my app? 
Thanks for you helps so much.

Hi everyone, when I using sf cmd to create a package : sf package version create --package $PACKAGENAME ..., I get an error like this: Error: default level:DEBUG must be included in custom levels.

Can you take some helps? Thank you so much.

I create objects in my scratch org and pull them to my source code. When that scratch org is expired, I deploy these objects to new scratch org, I have to set field-level for all the fields i have created. How can we set all the field-level by default when pushing them to new scratch org?

Thanks for you help.

Hello everyone, I want to create an Object to store the Settings of the user in my App. Is there any way to prevent user from creating a tab to see the records of this object and prevent them from changing it manually. 
Thanks for your helps.

Hi everyone, does Salesforce support any Rest API to create task and assign to multiple Users? And when I create a task and assign to multiple Users by using Lightning Experience, Salesforce will create multiple records, when I update one of these records, how all the other are updated too? 
Thanks for your helps.
Hi everyone, I want to create some user for my scratch using sfdx cli, I found a cmd is sfdx force:user:create but this command is just for 1 user 1 time. Can I use command: sfdx force:data:tree:import for import some Users into scratch org? Can you suggest me some solutions? 

Hi everyone, I have a problem when import user data into sratch org, I got this error: There are no available user licenses for the user profile "Standard User".

Here is my data about User got from User Definition File of Salesforce document:
{
    "Username": "tester1@sfdx.org",
    "LastName": "Hobbs",
    "Email": "tester1@sfdx.org",
    "Alias": "tester1",
    "TimeZoneSidKey": "America/Denver",
    "LocaleSidKey": "en_US",
    "EmailEncodingKey": "UTF-8",
    "LanguageLocaleKey": "en_US",
    "profileName": "Standard Platform User",
    "permsets": ["Dreamhouse", "Cloudhouse"],
    "generatePassword": true
}
Can anyone help me with this problem? I also have a question that I want to import tasks into Scratch org using sfdx force data tree import, how can I assign one of the user I've created into these tasks?
Thank you so much for your help.

I create custom fields for task by add custom field to Activity object and add all the custom fields to my package. I install that package in another org but it does not add these fields to page layout of Task, how can I solve this problem or I have to create a new page Layout and add it to my package? 
I have to create an AppExchange to management task, the Task standard object can not add custom field. My first idea for this problem is create a new custom object (MyApp Task) that have many custom field, and migrate all the records of Task (standard object) to MyApp Task. How can I do this? And when customer install my appexchange, does the records migrate to? Or can you suggest any ideas? Thank you so much.
I want to add custom field: StartDate to Task (Salesforce Standard object) but the salesforce does not allow that. Is there any solutions for this problem? 

Hi everyone, when I using sf cmd to create a package : sf package version create --package $PACKAGENAME ..., I get an error like this: Error: default level:DEBUG must be included in custom levels.

Can you take some helps? Thank you so much.

Hi everyone, does Salesforce support any Rest API to create task and assign to multiple Users? And when I create a task and assign to multiple Users by using Lightning Experience, Salesforce will create multiple records, when I update one of these records, how all the other are updated too? 
Thanks for your helps.
I create custom fields for task by add custom field to Activity object and add all the custom fields to my package. I install that package in another org but it does not add these fields to page layout of Task, how can I solve this problem or I have to create a new page Layout and add it to my package? 
I want to add custom field: StartDate to Task (Salesforce Standard object) but the salesforce does not allow that. Is there any solutions for this problem?