function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rishav Dutta 12Rishav Dutta 12 

I need help in the below apex code.

Hello, I am new to Apex coding... So am having some issues with syntax. 

Variables declared:

String Attribute10__c='Sample String 1';
String Attribute1__c='Sample String 2';
String Attribute3__c='Sample String 3';
String subject__c=''Sample String 4;
String Attribute11__c;
Integer cal_length;
Integer no_of_chars_from_case_tittle;
String case_tittle_length;

Logic to be implemented:

cal_length = 50 + Attribute10__c.length()+ Attribute1__c.length() + Attribute3__c.length();               
case_tittle_length = subject__c.length();
if (case_tittle_length <= 140-cal_length ) 
no_of_chars_from_case_tittle = case_tittle_length ;
else 
no_of_chars_from_case_tittle = 140-cal_length ;
Attribute11__c = subject__c.substring(0, no_of_chars_from_case_tittle);

I need help in constructing a apex code that I can execute in Workbench. I would like to get the values of Attribute11 and no_of_chars_from_case_tittle through system debug. Can anyone please help?
Best Answer chosen by Rishav Dutta 12
VIGNESH BALASUBRAMANIANVIGNESH BALASUBRAMANIAN
Hi Rishav,
 
String Attribute10__c='Sample String 1';
String Attribute1__c='Sample String 2';
String Attribute3__c='Sample String 3';
String subject__c=''Sample String 4;
String Attribute11__c;
Integer cal_length;
Integer no_of_chars_from_case_tittle;
String case_tittle_length;



cal_length = 50 + Attribute10__c.length()+ Attribute1__c.length() + Attribute3__c.length();               
case_tittle_length = subject__c.length();
if (case_tittle_length <= 140-cal_length ) 
{
no_of_chars_from_case_tittle = case_tittle_length ;
System.debug(no_of_chars_from_case_tittle );
}
else 
{
no_of_chars_from_case_tittle = 140-cal_length ;
System.debug(no_of_chars_from_case_tittle );
}
Attribute11__c = subject__c.substring(0, no_of_chars_from_case_tittle);

System.debug(Attribute11__c );

Check this...

All Answers

VIGNESH BALASUBRAMANIANVIGNESH BALASUBRAMANIAN
Hi Rishav,
 
String Attribute10__c='Sample String 1';
String Attribute1__c='Sample String 2';
String Attribute3__c='Sample String 3';
String subject__c=''Sample String 4;
String Attribute11__c;
Integer cal_length;
Integer no_of_chars_from_case_tittle;
String case_tittle_length;



cal_length = 50 + Attribute10__c.length()+ Attribute1__c.length() + Attribute3__c.length();               
case_tittle_length = subject__c.length();
if (case_tittle_length <= 140-cal_length ) 
{
no_of_chars_from_case_tittle = case_tittle_length ;
System.debug(no_of_chars_from_case_tittle );
}
else 
{
no_of_chars_from_case_tittle = 140-cal_length ;
System.debug(no_of_chars_from_case_tittle );
}
Attribute11__c = subject__c.substring(0, no_of_chars_from_case_tittle);

System.debug(Attribute11__c );

Check this...
This was selected as the best answer
Rishav Dutta 12Rishav Dutta 12
But am getting the error:
COMPILE ERROR: Invalid identifier: Attribute10__c
LINE: 1 COLUMN: 8
VIGNESH BALASUBRAMANIANVIGNESH BALASUBRAMANIAN
You have to put all these contents in method which is in class.And call the method by creating instance(Object) of that class...

Try this it works.....