I'm new to apex and I am trying to amend code left by our old developer. On our object "action plan" we have a series of rules that apply to all. I need to change this so when the "project" field is set to a specific name, a different time period is allowed.
Need to insert a condition that this 91 day is expanded to 182 days when project__c is a specific name.
Have tried to muddle my way through using IF functions but my syntax is wrong.
if(ap.Date__c > (AP.CreatedDate + 91) ){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error, Action Plan was created more than 3 months ago'));
return null;
}
Error messages have all been about syntax (";" expected where } was found" etc.,) though when I make suggested changes, often contradictory error messages are presented about the syntax.
Related
Basically I have a client request to implement:
Need to show data from the following fields : PaymMode, BankChequeNum, LedgerDimensionName, JournalNum from ledgerJournalTrans table on the LedgerTransVoucher form but have been unable to do so have tried nearly all of the possible queries that I could think of but none of them are working the way I expect them to: either the query is doing a cartesian product and duplicating the records or it is displaying no data in those fields.
Below is the query that I have recently tried:
public display MH_AccountTitle displayBeneficiaryName(GeneralJournalAccountEntry _accountEntry)
{
select SubledgerVoucher, AccountingDate from journalEntry
where journalEntry.RecId == _accountEntry.GeneralJournalEntry
join Voucher, MH_AccountTitle, RecId, AmountCurDebit, AmountCurCredit, TransDate from LedgerTrans
where LedgerTrans.Voucher == journalEntry.SubledgerVoucher
&& LedgerTrans.TransDate == journalEntry.AccountingDate
&& LedgerTrans.PaymReference == _accountEntry.PaymentReference
&& (abs(_accountEntry.TransactionCurrencyAmount) == LedgerTrans.AmountCurDebit
|| abs(_accountEntry.TransactionCurrencyAmount) == LedgerTrans.AmountCurCredit);
return ledgerTrans.MH_AccountTitle;
}
I know this query is logically incorrect because joins can't be applied on the basis of date and amount but this was suggested by a senior of mine after all else failed, and it did work, records were returned correctly but it failed where there were multiple transactions with same TransactionCurrencyAmount,TransDate and voucher
join with PaymentReference also failed where the method of payment was not Check and hence there was no BankChequeNum/Payment reference resulting in the same problem
Anyone who has any idea of what could be work around for this?
Note:
work has been done on a custom form of LedgerTransVoucher
display method approach was used because simply applying joins on the form's data source didn't work
Also code has been written on form's datasource GeneralJournalAccountEntry
What I usually do to debug these kinds of issues is get the query string that X++ creates when using inline SQL. Often there is something that X++ translates into SQL that is not expected.
Secondly, I always write my queries in SSMS first to avoid having unwanted results because of the X++ translation to SQL query.
You can get the query string by either making a query object and using the .ToString() method or you can take a trace and use Traceparser to view the query that was sent to the SQL Server.
I am thinking the abs() functions will be the issue here.
I am trying to count all the results that match multiple Where conditions in Salesforce. All these Where conditions exist under the same object that I am selecting from. It seems like it should be a simply query but my SQL and SOQL experience is limited.
Here's my code right now:
SELECT count() FROM Account
WHERE Success__c='yes'
AND Active__c='true'
AND Days__c>'30'
AND Days__c<'37'
It'd be useful to see the actual error message, but at a guess, you have quotes around things that shouldn't have them, e.g. you want
SELECT count() FROM Account
WHERE Success__c = 'yes'
AND Active__c = true
AND Days__c > 30
AND Days__c < 37
Also there are tools like SoqlX, the Force.com IDE and Workbench that'll let you run queries, so if Geckoboard is hiding the actual error message, you can work through getting a good query in one of these tools first.
To all salesforce experts i need some assistance. I have my contacts and a custom object named programs. I created a junction object using to master detail relationships with contacts and programs. I want to avoid relating the same contact to the same program. I tried triggers but I couldn't create the testing part to use it outside sandbox.
I went back to the basics and created a Unique text field. I tried to use default value but EVERYTHING i write in that crap is wrong -_-. I tried Contact__r.Email & "-" & Program__r.Name but to no avail.
I tried workflow rules with a field update but my field update NEVER runs.(Yes I did activate the workflow rule) and I didn't know what to write in my rule's code.
The workflow firing condition could be simply a formula that says true. Alternatively use "every time record is inserted". It also depends whether your master-details are set once and that's it or they will be "reparentable" (option introduced in Summer '12 I think). Maybe post a screenshot / text description of your firing condition? Also - is your unique field set to "case sensitive"?
As for the formula to populate the unique field - something like Contact__c + ' ' + Program__c (or whatever the API names of your fields are) should be OK. Don't use Contact__r.Email etc as these don't have to be unique...
You'll have to somehow fill in the uniqueness criteria for all existing records (maybe that's why you claimed it doesn't work?). If you can use Apex for data fixes - something like this should get you started.
List<Junction__c> junctions = [SELECT Contact__c, Program__c
FROM Junction__c
WHERE Unique_Text_Field__c = null
LIMIT 10000];
for(Junction__c j : junctions){
String key = String.valueOf(j.Contact__c).left(15) + ' ' + String.valueOf(j.Program__c).left(15);
j.Unique_Text_Field__c = key;
}
update junctions;
Keep rerunning it until it starts to show 0 rows processed. The Ids are cut down to 15 chars because in Apex you'd usually see full 18-char Id but workflows use 15-char versions.
Like I said in the topic,
My team developed social website based on Zend Framework (1.11).
The problem is that our client wants a debug (on screen list of DB queries) with
execution time, how many rows were affected and statement sentence.
Time and statement Zend_DB_profiler gets for us with no hassle, but
we need also the amount of rows that query affected (fetched, update, inserted or deleted).
Please help, how to cope with this task?
This is the current implementation which prevents you from getting what you want.
$qp->start($this->_queryId);
$retval = $this->_execute($params);
$prof->queryEnd($this->_queryId);
Possible solution would be:
Create your own class for Statement, let's say extended from Zend_Db_Statement_Mysqli or what have you.
Redefine its execute method so that $retval is carried on into $prof->queryEnd($this->_queryId);
Redefine $_defaultStmtClass in Zend_Db_Adapter_Mysqli with your new statement class name
Create your own Zend_Db_Profiler with public function queryEnd($queryId) redefined, so it accepts $retval and handles $retval
SOQL query not returning rows on visualforce page that do exist in object I am having issues retrieving records which exist from an object via a SOQL query on a visualforce page
How do I know they exist? I have used force explorer and workbench and the following returns a record
SELECT Code__c FROM External_membership_label__c WHERE Code__c = '3'
OK, so the visualforce page does not return the record above, with the code below (few lines from code)
public String gvlLCCODE {get;set;}
if(gvlLCCODE != null || gvlLCCODE != ''){
List<External_membership_label__c> exisitingGVLcodes = [SELECT Code__c FROM External_membership_label__c WHERE Code__c = :gvlLCCODE];
if (exisitingGVLcodes.Size() > 0){
//blahh blahh
}
}
Any suggestions? I have debug telling me 'gvlLCCODE' has a value that exists in the object. Also, if I change the SOQL to say, for example, return the current user from the users table, it returns a record and then enters the IF statement.
I think its a security issue I have missed. But I have also checked these.
Thank you
well, for one, in your IF statement you probably want to use &&, instead of ||.
Are you having the problem with the test method? if so, then it's because that method doesn't have access to the existing records by default.
First of all you should listen to Kirill about the &&, both condtions should be met, not just one. Likewise, the || is meaningless, formula (a!=b)|(a!=c) is always true for any a when b!=c as is the case here
Second, it sounds as you definitely have a security issue here. To verify change extension's declaration from with sharing to without sharing and run. If you get the row you have sharing security issues with the row.