Salesforce coding lessons for the 99%
Preface: this post is part of the SOQL: A Beginner’s Guide series.
SOQL is Salesforce’s official object query language. It’s based on SQL, one of the most popular database programming languages ever!
In a nutshell, SOQL is just a tool that lets you access anything about any record in your Salesforce database. Here’s an example:
SELECT Id, Name, Email, AccountId FROM Contact
In the above code, we’re using SOQL to access those four fields for every contact in Salesforce!
(You may have seen something similar when using Data Loader – that uses SOQL in the background!)
And that’s it – you already know 75% of SOQL, it’s really easy to learn!
Here’s why SOQL is significant:
Next post: Where to write SOQL queries
upload a video o soql join.Then we can understand easily.
Thank You
It’s there in Apex Academy #3!
David
Apex Trigger:
trigger ResultCandidate on CandidateResult__c (before insert) {
CandidateResult__c result=Trigger.new[0];
integer i = 0;
Candidate__c cc;
List c= new List();
c=[SELECT Name,Result__c FROM Candidate__c];
Iterator candidates =c.iterator();
while (candidates.hasNext())
{
cc=candidates.next();
if(cc.Name.isequals(result.CName__c))
{
UpdateCandidateResult.changeResult(result,cc);
}
}
}
Apex Class:
public class UpdateCandidateResult{
public static void changeResult(CandidateResult__c r,Candidate__c c){
if(r.InterviewResult__c==’Cleared’)
{
c.Result__c=’Pass’;
}
if(r.InterviewResult__c==’Partially Cleared’)
{
c.Result__c=’On Hold’;
}
if(r.InterviewResult__c==’Failed’)
{
c.Result__c=’Fail’;
}
update c;
}
}
Hi David,
i am Srinivas and very new to salesforce.com. i was just started 1 week ago and tried to write this code…
when i tried to save the trigger,,i got an error like..
Method does not exist or incorrect signature: [String].isequals(Id) at line 12 column 18
Exactly what my question is…how to access a master field using detail reference??? it would be very helpful for me..if u answer this question.i’m just started to follow ur site,it was really helping alot.
Another question Does Sandox appear default in any edition or not?? because i didnt find any sandbox under deploy.
Thanks in advance…
Try this!
cc.Name = result.CName__c.Name;
An Opp (child) and Account (master) have a master-detail relationship. If you’re on an Opp, you can reference the Account field by going like this:
myOpp.Account.Name;
This tutorial will help you understand this!
https://www.sfdc99.com/2013/06/09/example-how-to-write-a-cross-object-soql-query/
Also – sandboxes are only on paid editions! So can’t deploy if you’re on developer edition unfortunately!
David
P.S. sorry there is a delay when posting a comment – I manually approve comments because there is a lot of spam!
Hi David,
This is samyuktha, am unable to get notes on SOQL and trigger to get good knowledge on it, basically am interested to learn it
If you help me out in this it will more appreciable.
Is this site insufficient? =)