You need to sign in to do that
Don't have an account?

how to retrieve lookup relation values from soql
I have a lookuprelation in obj1(Registration__c), Now on insert i need to create a record on obj2(OutPatient__c) with lookup relation object values.
here is my code.
trigger Outrecord on Registration__c (after insert) {
public string DName;
List<OutPatient__c> lop = new List<OutPatient__c>();
Doctor__c doc = new Doctor__c();
for(Registration__c reg : trigger.new)
{
system.debug(reg.name);
if(reg.OutPatient__c==true)
{
OutPatient__c op = new OutPatient__c();
op.Name=reg.Name__c;
op.RegNumber__c=reg.Name;
DName= [select Doctor__r.Name__c from Registration__c rgt where rgt.Doctor__r.Name =:reg.DoctorName__c];//this query is not working.
op.DoctorName__c = DName;
lop.add(op);
}
insert lop;
}
Error:Didn't understand relationship 'Doctor__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Registration__c is custom object having doctor__c has lookuprelation.
I required Name__c from Doctor__c in obje2(outpatient__c) while i insert a record in Registration__c
Thanks in advance.
here is my code.
trigger Outrecord on Registration__c (after insert) {
public string DName;
List<OutPatient__c> lop = new List<OutPatient__c>();
Doctor__c doc = new Doctor__c();
for(Registration__c reg : trigger.new)
{
system.debug(reg.name);
if(reg.OutPatient__c==true)
{
OutPatient__c op = new OutPatient__c();
op.Name=reg.Name__c;
op.RegNumber__c=reg.Name;
DName= [select Doctor__r.Name__c from Registration__c rgt where rgt.Doctor__r.Name =:reg.DoctorName__c];//this query is not working.
op.DoctorName__c = DName;
lop.add(op);
}
insert lop;
}
Error:Didn't understand relationship 'Doctor__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Registration__c is custom object having doctor__c has lookuprelation.
I required Name__c from Doctor__c in obje2(outpatient__c) while i insert a record in Registration__c
Thanks in advance.
Try with below code it will help !!
Let me know if it helps
Thanks
Manoj
All Answers
There are some thing you need to check
1. Your query has rgt after Registration__c , please remove this.
2. Make sure you have name__c field on doctor object (You can use Doctor__r.Name only in your query.)
3. Make sure Doctor__c is parent of registraion__C.
try this code ,
Thanks
Prosenjit
1. Doctor__c is parent of registraion__C.(I am abit confused plz clear me, in Registration object i created a custom field lookup with object Doctor.So it confirms that Doctor__c is parent of Registration right).
@Prosenjit
I just copied your code even though i am getting the same error like
Didn't understand relationship 'Doctor__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Need a bit more help
Thanks in advance.
Try with below code it will help !!
Let me know if it helps
Thanks
Manoj
Check the relationship name of doctor and registration. You can see that in this way.
Setup -> Create -> Object -> Registration.
Go to Doctor Field .
Check relationship name.
Now please elaborate your requirement a bit more that what you want to do actually ?
Thanks
Prosenjit.
Prabhat Kumar12 Thank you all for encouraging me.
This is my Registration object details.
here DoctorName__c takes the autonumber(Standardfield)of the Doctor__c object.
Now on insert of Registration object with outPatient == true i need to create a outpatient record.
like this .
The thing,I am able to create the record but in the field DoctorName__c.I require the exact DoctorName not the ID of the particular Doctor.
Plz can any one explain me how the relations are taken into account while we are querying..I am totally confused.
Thanks in advance.
Try with below code it will help .
I have done some silly mistakes in previous codes :P
please try with this ,
Thanks
Prosenjit
this is the output..:-(
Even i too got the same output before.
Thanks
Is the code running or you are geting exception ? If codein is running check your Registartion record and its acosiated Docro Record that there is any empty field or not.
Thanks
Prosenjit