• Akshay Ambhure
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Kindly help me out with below code
Except Error message functionality all working

//VFP
<apex:page controller="NumberClassErrorMessage" wizard="true">
    <apex:form >
        <apex:pageBlock title="Number Calculations">
            <apex:pageMessages id="showmsg"></apex:pageMessages>
            
            <apex:pageBlockSection title="Calculator" >
                <font color="#E70E38">
                Enter Number 1: <apex:inputText value="{!Num1}" />
                Enter Number 2: <apex:inputText value="{!Num2}"/>
                    </font>
                <apex:commandButton value="Calculate" action="{!calculator}" reRender="xyz" />
                <apex:outputLabel id="xyz" value="{!SUBSTITUTE(JSENCODE(message), '\\n', '<br/>')}" escape="false" />       
            </apex:pageBlockSection>    
        </apex:pageBlock>
    </apex:form>    
</apex:page>

//APEX
public class NumberClassErrorMessage {
    
    public integer Num1 {set; get;}
    public integer Num2 {set; get;}
    public string message {set; get;}
    public void calculator()
    {
        integer add,sub,mul,div ;
        
        //if(acc.AccountNumber == '' || acc.AccountNumber == null)
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number'));
        /*if(NumberA < 0){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'First number is negative!'));
}
*/      
        if(Num1 == null || Num1 < 0){
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Kindly Enter Valid Amount in Number 1'));
            
        }
        if(Num2 == null || Num2 < 0){
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Kindly Enter Valid Amount in Number 2'));
        }
        
        add = Num1+Num2;
        sub = Num1-Num2;
        mul = Num1*Num2;
        // div = Num1/Num2;
        
        message = 'Addition of Numbers :' +add + '\n' + 
            'Substraction of Numbers :' +sub +  '\n' +
            'Multiplication of Numbers :' +mul +  '\n' +
            'Division of Numbers :'  ; // +div
    }
}
Hello,

This is the trailhead questions which I am trying to solve :

Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.


Here is my code :

public class StringArrayTest {
    public static List <String> generateStringArray (Integer n) {
       List<String> List1 = new List<String> ();
        for(Integer i=0;i<n;i++) {
          List1.add('\'Test'+ i+'\'' );
  }
        System.debug(List1);
        return List1;
    } 

}


I am getting following error :

Challenge not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.


I tried it many times but I am not able to solve this problem. Please help. 



 

I have a trigger with recursive control that performs both Before Insert and Before Update, but I cannot figure out how to test the Before Update in my test class.  When I insert the test data in my unit test, the recursive variable is set to true and will block my update from setting off the trigger.  This is only desirable for when it runs in production, but not when I need to insert data in order to test situations where existing data is being updated.  I even tried inserting the test data above the test.startTest() line.  But this does not matter since every action in the test method occurs in the same context.

 

How do I write my test class to cover this?

 

 

Trigger code: 

 

trigger PriceModifierTrigger on OpportunityLineItem (before insert, before update) {

	if(!PriceModifierClass.hasAlreadyRunMethod()){
		if(trigger.isBefore && trigger.isInsert){
			PriceModifierClass.sortOppProducts(trigger.new, trigger.oldMap, 'Insert');
		}
		if(trigger.isBefore && trigger.isUpdate){
			PriceModifierClass.sortOppProducts(trigger.new, trigger.oldMap, 'Update');
		}
		PriceModifierClass.setAlreadyRunMethod();	
	}
}

 

 

Excerpt from class:

public static boolean hasAlreadyRun = false;
	
	public static boolean hasAlreadyRunMethod(){
		return hasAlreadyRun;
	}
	
	public static void setAlreadyRunMethod(){
		hasAlreadyRun = true;
	}

 

Hi all

  I have created Visualforce page for PDF usage. I have listed some Rich text values from controller class like given below

<page  standardController="Shipment_Header__c">

<apex:outputText value="{!PackingSlipSignature}"/>

</page>

 

The 'packingSlipSignature'  Return some company address from controller class. This i want dispaly one by one but this  display as given below

CompanyName<br> RK Salai<br> chennai<br> <br>

 

What can i do for this.