• Benjamin Zerbib 3
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Hello everybody!

I have an issue while trying to deploy an Apex Class triggered by a Process Builder.
Here is my code: 
public class CMC_Automation_Code {
    
    @InvocableMethod
    public static void updateAccount(List<String> AccountIds){
        Integer CMC_Value = 0;
        
        List<Account> AllAccounts = [SELECT Id, CMC_Auto_Number__c FROM Account where Id in:AccountIds AND CMC_Auto_Number__c = 0];
        if(AllAccounts != null && AllAccounts.size()>0){
        List<Account> AccList = [SELECT Id, CMC_Auto_Number__c, CreatedDate FROM Account where CMC_Auto_Number__c != null
                                 order by CMC_Auto_Number__c desc limit 1];
        if(AccList != null && AccList.size()>0){
                CMC_Value = integer.valueof(AccList[0].CMC_Auto_Number__c +1);
           }
        for(Account Acc:AllAccounts){
            Acc.Global_Account_ID__c = 'CS-' + String.valueOf(CMC_Value);
        Acc.CMC_Auto_Number__c = CMC_Value;
            CMC_Value ++;
        }
        
        update AllAccounts;
    }
}

}

And here is the error message I get while trying to 'Validate' the Outbound Change Set: 
User-added imageSystem.Exception: Assertion Failed
Stack Trace: Class.test_updatecontactrolecount.testcreateopptywithconditionandrole: line 38, column 1


Could you please help me out?

Thanks a lot!
Benji
Hello everybody!

I created an Apex Class that is triggered through a Process Builder when an Account is created or updated.
The conditions for the Process Builder to trigger the Apex Class are:
- Is the Account Status = Active
AND
- is the Account Type = Customer

The Apex Class is the following: 
public class CMC_Automation_Code {
    
    @InvocableMethod
    public static void updateAccount(List<String> AccountIds){
        Integer CMC_Value = 0;
        Account con=[SELECT Id, CMC_Auto_Number__c FROM Account where Id in:AccountIds];
        List<Account> AccList = [SELECT Id, CMC_Auto_Number__c, CreatedDate FROM Account where CMC_Auto_Number__c != null
                                 order by CMC_Auto_Number__c desc limit 1];
        if(AccList != null && AccList.size()>0){
                CMC_Value = integer.valueof(AccList[0].CMC_Auto_Number__c +1);
           }
        con.Global_Account_ID__c = 'CS-' + String.valueOf(CMC_Value);
        con.CMC_Auto_Number__c = CMC_Value;
        update con;
    }

}

When I create an Account manually, or, when I update an Account manually it is working perfectly.
But, when I try to create a lot of Accounts via the Data Loader, I get the following error message: "
We can't save this record because the “Active Customer Account Process” process failed. Give your Salesforce admin these details. An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject
 Error ID: 1551401632-444116 (302225672)
"

I don't really understand the error message nor the issue.

Could somebody help me, please?

Thanks a lot!

Benji
Hello everybody!

I have a short Apex Class that is supposed to paste a number in a Text field.
it's working but my issue is that it is pasting the number with a decimal value (example: '3.0' instead of '3').

How can I resolve this small issue, please?

Here is my code in case you need it:
 
public class CMC_Automation_Code {
    
    @InvocableMethod
    public static void updateAccount(List<String> AccountIds){
        Double CMC_Value = 0;
        Account con=[SELECT Id, CMC_Auto_Number__c FROM Account where Id in:AccountIds];
        List<Account> AccList = [SELECT Id, CMC_Auto_Number__c, CreatedDate FROM Account where CMC_Auto_Number__c != null
                                 order by CreatedDate desc limit 1];
        if(AccList != null && AccList.size()>0){
                CMC_Value = AccList[0].CMC_Auto_Number__c +1;
           }
        con.Global_Account_ID__c = 'CS-' + String.valueOf(CMC_Value);
        update con;
    }

}

Thanks a lot!

Benji​​​​​​​
Hello everybody!
I have a custom object (Signoff) connected to Opportunity through a Master-Detail relationship.
On Signoff, there is a field called Currency. I would like to make sure that if the Currency field on Opportunity is 'US Dollar' for example, the Currency field on Signoff must be automatically updated to 'US Dollar'.

I tried to make it through a Workflow but I can't update the Currency field on Signoff with a Workflow.

How to do it with code, please?

Thanks a lot
Benji
Hey Everybody!

I need some help for something:
I would like to know the number of Tasks per Opportunity so I could delete the first one when the number of Tasks is superior to 1.

I haven't developed any trigger before... Could somebody help me please?

Thanks in advance!

Ben
Hello everybody!

I have a short Apex Class that is supposed to paste a number in a Text field.
it's working but my issue is that it is pasting the number with a decimal value (example: '3.0' instead of '3').

How can I resolve this small issue, please?

Here is my code in case you need it:
 
public class CMC_Automation_Code {
    
    @InvocableMethod
    public static void updateAccount(List<String> AccountIds){
        Double CMC_Value = 0;
        Account con=[SELECT Id, CMC_Auto_Number__c FROM Account where Id in:AccountIds];
        List<Account> AccList = [SELECT Id, CMC_Auto_Number__c, CreatedDate FROM Account where CMC_Auto_Number__c != null
                                 order by CreatedDate desc limit 1];
        if(AccList != null && AccList.size()>0){
                CMC_Value = AccList[0].CMC_Auto_Number__c +1;
           }
        con.Global_Account_ID__c = 'CS-' + String.valueOf(CMC_Value);
        update con;
    }

}

Thanks a lot!

Benji​​​​​​​