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
Keer YenduriKeer Yenduri 

public class MyHelloWorld { public static void applyDiscount(Boook__c[] books) { for(Boook__c b:books) b.Prise__c*=0.9; } }

Hi,
public class MyHelloWorld
{

 

public static void applyDiscount(Boook__c[] books)
{
for(Boook__c b:books)
b.Prise__c*=0.9;
}
}
when i am trying to executive this class it's getting error,plz urgent.


Thanks!!
Best Answer chosen by Keer Yenduri
Anoop yadavAnoop yadav
Hi,

I tried at my end with the below code and it is working fine.
List<Boook__c> bookList = new List<Boook__c>();
Boook__c b = new Boook__c(Name = 'Test', Prise__c = 100);
bookList.add(b);
MyHelloWorld.applyDiscount(bookList);
System.debug('CHECK:'+bookList);
In Debug, you will get the prise value as 90.
If you still get the error try with firefox or Google Crome browser.

 

All Answers

Anoop yadavAnoop yadav
Hi,
What error you are getting?
First you should create a "Boook" object with  "Prise__c" field in salesforce.
After that write a tigger on that object, only then it will work.

Check the below link for more informatiom.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_HelloWorld.htm
 
Keer YenduriKeer Yenduri
Hi,

I created already and what my trigger is


trigger HelloWorldTrigger on Boook__c (before insert) 
{    
Boook__c[] books = Trigger.new;    
MyHelloWorld.applyDiscount(books);
}

this trigger is right r wrong?
please let me know.


 
Anoop yadavAnoop yadav
Yes, this is correct.
What error you are getting?
are you putting any value in "Prise__c" field before inserting the record?
Keer YenduriKeer Yenduri
Hi,
Annop

that example is what u sent it to me i.e i am trying with the same example only,it's showing error when i am executing that class.
may be "boooks__c" i took array of custom object.


Thanks!!
 
Anoop yadavAnoop yadav
What is your error?
And how you are Executing this class?
Keer YenduriKeer Yenduri
Hi Anoop r u der?

plz let me know.
Anoop yadavAnoop yadav
What is your error?
And how you are Executing this class?
Keer YenduriKeer Yenduri
Hi,

i am getting dis err

"
Method does not exist or incorrect signature: MyHelloWorld.applyDiscount()
"


 
Anoop yadavAnoop yadav
How you are calling this method?
Keer YenduriKeer Yenduri
Hi,
MyHelloWorld.applyDiscount();

in developer consle.
Anoop yadavAnoop yadav
You Should create a tab for Boook object.
and when you insert the boook record it will call that method.

If you want to execute from developer console Use the below code.
List<Boook__c> bookList = new List<Boook__c>();
Boook__c b = new Boook__c(Name = 'Test', Prise__c = 100);
bookList.add(b);
MyHelloWorld.applyDiscount(bookList);

 
Keer YenduriKeer Yenduri
Hi;


Long running operation did not complete, continuing in background

this type of error is comming.
Anoop yadavAnoop yadav
Download the debug file
or check by creating the tab.
 
Keer YenduriKeer Yenduri
Hi,
i downloaded the log
i.e
32.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
23:35:00.031 (31928455)|EXECUTION_STARTED
23:35:00.031 (31977804)|CODE_UNIT_STARTED|[EXTERNAL]|VisualForce View State
23:35:00.040 (40676008)|CODE_UNIT_FINISHED|VisualForce View State
23:35:00.041 (41994745)|EXECUTION_FINISHED
23:35:01.310 (353857755)|CUMULATIVE_LIMIT_USAGE
23:35:01.310|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

23:35:01.310|CUMULATIVE_LIMIT_USAGE_END

 
Anoop yadavAnoop yadav
What you want to do?
and what result you are expecting?
Keer YenduriKeer Yenduri
Hi,
Anoop first i want to execute the class den i will k with my class.
if it is executed den i will think that class is correct.
So i want to execute that class
see
first i created the custom object and custom fields for that
next i wrote trigger and class,
in my way of thinking if class works proprly den my work is done
 
Anoop yadavAnoop yadav
To check the above class you should follow some more steps.

Create a tab for the above object by SetUp==>Tabs
click on new in "Custom Object Tabs", select the object and save.
After that you will get a Boook tab in tab panel.
Click on the tab, create new record, enter the name and price
after saving the record price value will be multiplied by 0.9.
Let me know if you neeed more help.
 
Keer YenduriKeer Yenduri
Hi,

Okay Anoop i created like that only and what i am saying is i want to execute class alone i want to check whther it is working r not
u gave code for developer console i tried with that after that i got the error
like"Long running operation did not complete, continuing in background"
is it error r is it work backend?
is it showing like?
and when created records for Boook__c object creating the records
and so is our job done without getting any error for record creation?
i want that.

Thanks!!!

 
Anoop yadavAnoop yadav
The above one is not an error.
Can you run that again and let me know.

or run the below code
Boook__c[] bookList = new Boook__c[];
Boook__c b = new Boook__c(Name = 'Test', Prise__c = 100);
bookList.add(b);
MyHelloWorld.applyDiscount(bookList);


 
Keer YenduriKeer Yenduri
Hi,
Again i tried,
But
i got this error
ERROR:in developer console
expecting left curly bracket, found ';'
with this code when i am executing

Boook__c[] bookList = new Boook__c[];
Boook__c b = new Boook__c(Name = 'Test',Prise__c = 100);
bookList.add(b);
MyHelloWorld.applyDiscount(bookList);

And  i am saying u
what are my components are:

1)
Objectname:Boook   APIname:Boook__c
Fieldname:Prise     APIname:Prise__c


2)
trigger HelloWorldTrigger on Boook__c (before insert)
{
Boook__c[] books = Trigger.new;
 MyHelloWorld.applyDiscount(books);
}

3)
public class MyHelloWorld
{
public static void applyDiscount(Boook__c[] books)
{
for(Boook__c b:books)
{
b.Prise__c*=0.9;
}
}
}

4)
DeveloperConsole:
Boook__c[] bookList = new Boook__c[];
Boook__c b = new Boook__c(Name = 'Test',Prise__c = 100);
bookList.add(b);
MyHelloWorld.applyDiscount(bookList);

Please let me know the solution for that.

Thanks!!!!











 
Anoop yadavAnoop yadav
Hi,

I tried at my end with the below code and it is working fine.
List<Boook__c> bookList = new List<Boook__c>();
Boook__c b = new Boook__c(Name = 'Test', Prise__c = 100);
bookList.add(b);
MyHelloWorld.applyDiscount(bookList);
System.debug('CHECK:'+bookList);
In Debug, you will get the prise value as 90.
If you still get the error try with firefox or Google Crome browser.

 
This was selected as the best answer
Keer YenduriKeer Yenduri
Hi Anoop,

Thank u so much,it's working.
And may i know do u have hands on experience in webservices in salesforce?
why becoz now i am working in webservices so please let me know i have doubts.
Anoop yadavAnoop yadav
Sorry, I am not too good in webservices.
If you post any issue, you will get help from other developers as well.
Thanks
 
Keer YenduriKeer Yenduri
Hi,
Okay fine please let me know
 i will tell a scenario:
i create one customer in salesfroce and updates also willbe there
regarding this i want to write a trigger
i don't know how to write a trigger for this scenarioo.
Keer YenduriKeer Yenduri
Hi Anoop,

Please help me out how to write that trigger regarding that scenario.