+ Start a Discussion
learn_sfdclearn_sfdc 

How to get custom object in to apex class

Hello Friends,

I am trying to retrive a data from Custom Object A to Standard Object B

for standard object i can use if function like below

 if(MoreCase.Account.Type != null && MoreCase.Account.Type != '')
            {
                if(MoreCase.Account.Type.contains('Customer')){
                    ShowCustomer = true;
                }else if(MoreCase.Account.Type.Contains('Ex-Customer')){
                    ShowExCustomer = true;

I am using Account object and type is field which standard object but for my custom object and field how would i use 

custom object  API Name - Product_Version_Master__c
field name is - Existing_Version 

how will i use this in my function?

Thanks
 
Best Answer chosen by learn_sfdc
rajat Maheshwari 6rajat Maheshwari 6

Shruthi,

Use this query as below : - 

MoreCase = [Select c.Product_Version_Master__r.Existing_Version
                     from Case c where Id= :ViewingCase.Id];

 if(MoreCase.Account.Type != null && MoreCase.Account.Type != '')
            {
                if(MoreCase.Product_Version_Master__r.Existing_Version.contains('Customer')){
                    ShowCustomer = true;
                }else if(MoreCase.Product_Version_Master__r.Existing_Version.Contains('Ex-Customer')){
                    ShowExCustomer = true;

 

Note : - I am assuming, Custom object "Product_Version_Master__c" is parent and Case is child.

on Case, API Name of lookup field is "Product_Version_Master__c"

 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

All Answers

rajat Maheshwari 6rajat Maheshwari 6

Hi Shruti,

What the MoreCase represent ? 

Thanks

learn_sfdclearn_sfdc
Hi rajat,

MoreCase = [Select c.Account.Special_Support__c, 
                          c.Account.Type,
                          from Case c where Id= :ViewingCase.Id];

querying...
rajat Maheshwari 6rajat Maheshwari 6

Shruthi,

Use this query as below : - 

MoreCase = [Select c.Product_Version_Master__r.Existing_Version
                     from Case c where Id= :ViewingCase.Id];

 if(MoreCase.Account.Type != null && MoreCase.Account.Type != '')
            {
                if(MoreCase.Product_Version_Master__r.Existing_Version.contains('Customer')){
                    ShowCustomer = true;
                }else if(MoreCase.Product_Version_Master__r.Existing_Version.Contains('Ex-Customer')){
                    ShowExCustomer = true;

 

Note : - I am assuming, Custom object "Product_Version_Master__c" is parent and Case is child.

on Case, API Name of lookup field is "Product_Version_Master__c"

 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

This was selected as the best answer
rajat Maheshwari 6rajat Maheshwari 6

Please replace  if(MoreCase.Account.Type != null && MoreCase.Account.Type != '')

by if(MoreCase.Product_Version_Master__r.Existing_Version!= null && MoreCase.Product_Version_Master__r.Existing_Version!= '')

Thanks
Rajat

learn_sfdclearn_sfdc
will try this and get back to you rajat, thank you
 
learn_sfdclearn_sfdc
hi rajat,

i sent a mail to you, can you please check.

Thanks