• Andrey Bolkonsky
  • NEWBIE
  • 40 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 7
    Replies
I am still very new to writing code and am currently studying the Apex Developer guide page by page. I really could use some help undertanding what properties are for. 

The guide gives the following examples but really doesn't do a good job of explaining what the point of using these things is and why you would use one instead of just declaring a variable like Integer i = 5;

Can someone shed some light on what these are helpful for or even share a practical use case for them? I am totally lost.
 
public Integer prop{
        get {return prop;}
        set {prop = value;}
    }
public Integer MyReadOnlyProp { get; }
public Double MyReadWriteProp { get; set; } 
public String MyWriteOnlyProp { set; }

 
Having problem sending email in my Opportunity Trigger Handler Class. The template uses merge fields from the Opportunity but TargetObjectId says it is only accepting Contacts, Leads and Users (this is a really stupid limitation by the way).

I don't want to put the Opportunity ownerId either becasue the email doesn't go to the opportunit owner, it goes to a list of support staff. Here is my code so far. Sorry it's a bit of a mess. Really trying to send as a template and not as a plain text email.

I have also tried to use the renderStoredEmailTemplate method but also with no success.

Please help!
 
if(Opp.StageName == 'Documentation' && stageFrom == 'Submission'){
                
                //Fix this TargetObjectID issue***
                Messaging.reserveSingleEmailCapacity(2);
                Messaging.SingleEmailMessage DocEmail = new Messaging.SingleEmailMessage();
                    
                EmailTemplate et =[SELECT Id, Name FROM EmailTemplate WHERE Name = 'Doc Stage'];
                DocEmail.setTemplateId(et.Id);
                DocEmail.setToAddresses(new String[] {'email1@company.com', 'email2@company.com'});
                DocEmail.setReplyTo('DocEmails@Company.com');
                DocEmail.setSenderDisplayName('Doc Automated Emails');
                DocEmail.setTargetObjectId(Opp.OwnerId);
                DocEmail.setWhatId(Opp.Id);
                DocEmail.setSaveAsActivity(FALSE);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {DocEmail});
                
            }

 
I have a new invocable apex class I am putting in a flow and Opportunity Amount is one of the inputs for the class.

The variables are passed into the flow through a custom button but it's not allowing me to pass Opportunity Amount into the either an Integer flow variable or a currency flow variables. 

The opportunity amount field has two decimal places and I have set both types of flow variables (int and currency) to also have two decimal places but it still says that:

The value $3,000,001.00 is being provided for variable AMT but isn't compatible with the variable's data type (Currency)

How do I make a flow variable compatible with Opportunity Amount field without making additional formulas fields.
I have some simple VF pages I am adding to the page layout of a custom object. They show up on the detail page and they show up when I click edit, however they are not showing up on the new record screen when I click the New button.

The VF pages are the text for questions I am asking and the object fields are the answers the users select. So in short, having them show up on the Create New Record screen is the most important part. 

I would normally just make a read only text field with the question as the default text, but am trying to get away from doing this as it impacts my custom field limit.

What am I doing wrong?

Here is an exame of one of the pages I am inserting on the page layout.
 
<apex:page standardController="Custom_Object__c">
  <apex:pageBlock >
  <apex:outputText >Sample Text</apex:outputText>
  <br/>
  <apex:outputText >A. Sample Text</apex:outputText>
  <br/>
  <apex:outputText >B. Sample Text</apex:outputText>
  <br/>
  <apex:outputText >C. Sample Text</apex:outputText>
  <br/>
  <apex:outputtext >D. Sample Text</apex:outputtext>
  <br/>
  <apex:outputText >Sample Text</apex:outputText>
  </apex:pageBlock>
</apex:page>

 
I have a custom detail page button that launches a flow, however validation rules do not work with custom buttons so I am going to have to use Javascript to Validate the record before it is passed into my flow.

I just learned Apex but know nothing about javascript. How would I turn the below button into a javascript button that won't allow users to access the flow unless certain fields are filled in?
 
/flow/Submission?AnRevID={!Annual_Review__c.Id}&OppID={!Annual_Review__c.OpportunityId__c}&AeID={!Annual_Review__c.Account_ExecutiveId__c}&PmID={!Annual_Review__c.Portfolio_ManagerId__c}&OppOwnerName={!Annual_Review__c.OppOwnerName__c}&OppOwnerID={!Annual_Review__c.OppOwnerID__c}&Status={!Annual_Review__c.Status__c}&AnRevName={!Annual_Review__c.Name}&AccountID={!Annual_Review__c.AccountId__c}&OPM={!Annual_Review__c.OPM__c}&OppName={!Annual_Review__c.Opportunity__c}&Product={!Annual_Review__c.Product__c}&OppOwnerState={!$User.State}

 
I've made a class that converts leads and also a Test Data Factory class that makes test leads.

However My below test class is not working. When I used System.Assert(), I get the error System.AssertException: Assertion Failed

When I used System.AssertEquals(Lead1.IsConverted, TRUE) I get the error System.AssertException: Assertion Failed: Expected: false, Actual: true

What am I doing wrong?
 
@isTest
global class ConvertLeadTest {

    @isTest
    static void convertOneLead(){
        
        Lead[] TestLeads = TestDataFactory2.getTestLeads(1);
        List<Id> IdsIn = new List<Id>();
        for(Lead Lead : TestLeads){
            IdsIn.add(Lead.Id);
        }
        
        insert TestLeads;
        
        Lead Lead1 = TestLeads[0];
       
        ConvertLead.LeadsToConvert(IdsIn);
        
        System.assert(Lead1.IsConverted);
    }
    
}

 
I am working on my second Invocable method I want to call within a flow and I am having trouble conceptualizing this.

I want to output 3 different integer values from the invocable method back out to the flow but I don't know how to do this if I can have only one Return statement.

My first invocable method took in one variable and output one value so it was easy.

How should I solve for this?
This is my second post trying to figure this out. I have a method of the return type string with one integer Parameter. It is my first Apex class so I want to make it invocable so that if something goes wrong with it I can just deactivate the flow. 

However I can't wrap my head around the invocable method annotation, specifically turning everything in my method into some kind of list. Can anyone explain how I might do this?
 
//@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
public static String writeNumber(Integer Amt) {
                Integer Amount=Amt;
                Integer Len;
                String spelledAmount;
                
                Map<Integer, String> numberName=new Map<Integer, String> { }; 
                
            String amountString=String.valueOf(Amount);
            Len=amountString.Length();
                
          List<Integer> arrayNumber=new List<Integer>();  
            String[] chars=amountString.split('');
            for(String c:chars) {
                    arrayNumber.add(Integer.valueOf(c));        
            }

           Switch on Len { }

//Body of method

return spelledAmount;

}



 
Hello,

I just finished my first ever Apex class (I am very new to this stuff). The main method I want to call has the return type of string. 

I want to write a trigger and also a flow to call it just so I know how to use both to trigger Apex. But When I try to use the @InvocableMethod anotation so I can launch it from a flow, I get the error

InvocableMethod methods do not support return type of String

Below is the firtst part of the method I want to call.
 
@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
            public static String writeNumber()

 
Another newbie quetion. I thought I was creating a List that took the value of my Integer variable "Amount" and put each digit as a value of the array. Instead I got the ASCII values! Not helpful at all.
 
public String writeNumber() {
            String amountString=String.valueOf(Amount);
            Len=amountString.Length();
                
            List<Integer> arrayNumber=new List<Integer>();
                for(Integer i=0; i <= Len - 1; i++) {
                arrayNumber.add(amountString.charAt(i));
                }
           }
If i put in 30567 for the value of Amount, I thought that {3, 0, 5, 6, 7} would be the values of my list but instead it is {51, 48, 53, 54, 55}. How can I get this to have the values that I want and not ASCII?
This is probably a very stupid question but I am very new to this. I cannot find a way to get the length of an integer in the sample below. I thought it would be Amount.length() or Amount.getLength but I keep gettin the error: Method does not exist of incorrect signature. Thanks.

 public String writeNumber(Integer a) {
            a=Amount;
            
            Integer len=Amount.getLength();
}
Having problem sending email in my Opportunity Trigger Handler Class. The template uses merge fields from the Opportunity but TargetObjectId says it is only accepting Contacts, Leads and Users (this is a really stupid limitation by the way).

I don't want to put the Opportunity ownerId either becasue the email doesn't go to the opportunit owner, it goes to a list of support staff. Here is my code so far. Sorry it's a bit of a mess. Really trying to send as a template and not as a plain text email.

I have also tried to use the renderStoredEmailTemplate method but also with no success.

Please help!
 
if(Opp.StageName == 'Documentation' && stageFrom == 'Submission'){
                
                //Fix this TargetObjectID issue***
                Messaging.reserveSingleEmailCapacity(2);
                Messaging.SingleEmailMessage DocEmail = new Messaging.SingleEmailMessage();
                    
                EmailTemplate et =[SELECT Id, Name FROM EmailTemplate WHERE Name = 'Doc Stage'];
                DocEmail.setTemplateId(et.Id);
                DocEmail.setToAddresses(new String[] {'email1@company.com', 'email2@company.com'});
                DocEmail.setReplyTo('DocEmails@Company.com');
                DocEmail.setSenderDisplayName('Doc Automated Emails');
                DocEmail.setTargetObjectId(Opp.OwnerId);
                DocEmail.setWhatId(Opp.Id);
                DocEmail.setSaveAsActivity(FALSE);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {DocEmail});
                
            }

 
I've made a class that converts leads and also a Test Data Factory class that makes test leads.

However My below test class is not working. When I used System.Assert(), I get the error System.AssertException: Assertion Failed

When I used System.AssertEquals(Lead1.IsConverted, TRUE) I get the error System.AssertException: Assertion Failed: Expected: false, Actual: true

What am I doing wrong?
 
@isTest
global class ConvertLeadTest {

    @isTest
    static void convertOneLead(){
        
        Lead[] TestLeads = TestDataFactory2.getTestLeads(1);
        List<Id> IdsIn = new List<Id>();
        for(Lead Lead : TestLeads){
            IdsIn.add(Lead.Id);
        }
        
        insert TestLeads;
        
        Lead Lead1 = TestLeads[0];
       
        ConvertLead.LeadsToConvert(IdsIn);
        
        System.assert(Lead1.IsConverted);
    }
    
}

 
This is my second post trying to figure this out. I have a method of the return type string with one integer Parameter. It is my first Apex class so I want to make it invocable so that if something goes wrong with it I can just deactivate the flow. 

However I can't wrap my head around the invocable method annotation, specifically turning everything in my method into some kind of list. Can anyone explain how I might do this?
 
//@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
public static String writeNumber(Integer Amt) {
                Integer Amount=Amt;
                Integer Len;
                String spelledAmount;
                
                Map<Integer, String> numberName=new Map<Integer, String> { }; 
                
            String amountString=String.valueOf(Amount);
            Len=amountString.Length();
                
          List<Integer> arrayNumber=new List<Integer>();  
            String[] chars=amountString.split('');
            for(String c:chars) {
                    arrayNumber.add(Integer.valueOf(c));        
            }

           Switch on Len { }

//Body of method

return spelledAmount;

}



 
Hello,

I just finished my first ever Apex class (I am very new to this stuff). The main method I want to call has the return type of string. 

I want to write a trigger and also a flow to call it just so I know how to use both to trigger Apex. But When I try to use the @InvocableMethod anotation so I can launch it from a flow, I get the error

InvocableMethod methods do not support return type of String

Below is the firtst part of the method I want to call.
 
@InvocableMethod(label='Write Number' description='Writes the Number' category='Opportunity')
            public static String writeNumber()

 
Another newbie quetion. I thought I was creating a List that took the value of my Integer variable "Amount" and put each digit as a value of the array. Instead I got the ASCII values! Not helpful at all.
 
public String writeNumber() {
            String amountString=String.valueOf(Amount);
            Len=amountString.Length();
                
            List<Integer> arrayNumber=new List<Integer>();
                for(Integer i=0; i <= Len - 1; i++) {
                arrayNumber.add(amountString.charAt(i));
                }
           }
If i put in 30567 for the value of Amount, I thought that {3, 0, 5, 6, 7} would be the values of my list but instead it is {51, 48, 53, 54, 55}. How can I get this to have the values that I want and not ASCII?
This is probably a very stupid question but I am very new to this. I cannot find a way to get the length of an integer in the sample below. I thought it would be Amount.length() or Amount.getLength but I keep gettin the error: Method does not exist of incorrect signature. Thanks.

 public String writeNumber(Integer a) {
            a=Amount;
            
            Integer len=Amount.getLength();
}