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
nikki goudanikki gouda 

fetch user details

How to fetch user details with user "(username,email)and opportunity(id,stagename) object fields based on username by using JSON 
Suraj Tripathi 47Suraj Tripathi 47

Hi Nikki,

So basically your question is a bit uncleared but still, I managed to solve it. So basically, I could think of two scenarios from your question.

 

1. I'm assuming that your are passing Username as params, if that is the case then use this:
 

public class FetchOppoUse{
    
    
    public static void getData(String uName){
        
        List<User> userDetail = [SELECT Id, Username, Email FROM User WHERE Username = :uName];
        set<Id>UserID = new set<Id>();
            
            for(user each : userDetail){
            UserID.add(each.Id);
        }
        
        List<opportunity> getAllData = [SELECT Id, StageName, CreatedById FROM Opportunity Where CreatedById IN :UserID];
        
        system.debug('userDetail : '+ userDetail);
        system.debug('getAllData : '+getAllData);
    }
    

}

2. If you are fetching all the data from the DB and you want them to return in JSON format, then you can try this:
public class FetchOppoUse{
    
    
    public static void getData(){
        
        List<User> userDetail = [SELECT Id, Username, Email FROM User];
        set<Id>UserID = new set<Id>();
            
            for(user each : userDetail){
            UserID.add(each.Id);
        }
        
        List<opportunity> getAllData = [SELECT Id, StageName, CreatedById FROM Opportunity Where CreatedById IN :UserID];
        
        system.debug('userDetail : '+ userDetail);
        system.debug('getAllData : '+getAllData);

    }
    

}


If you still feel like this Is not what you want then feel free to get back. I'll be happy to assist.

 

I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Suraj

nikki goudanikki gouda
Fetch the user details:
let us assume that our requirements

class: details
method:getdata
input:username
method shold be in JSON format array to fetch the user and opportunity information
if no records then return null
user object fields:username,email
opportinity fields: stagename,id
David HarborDavid Harbor
The location of enterprises across the nation has significantly changed as a result of Romania's outsourcing market's popularity and expansion. Bucharest, the capital of Romania, used to be a sought-after location for corporate headquarters (more about you can find here https://mobilunity.com/blog/hire-romanian-developers-or-ukrainian/). Many R&D centers are looking to university towns like Targu Mures and Craiova to set up shop as the IT sector continues to show continuous growth. They now have better access to Romanian developers who are educated. Young, driven developers from Romania are starting their careers at these R&D facilities right out of college. Therefore, these new locations outside of the nation's capital are advantageous for Romanian programmers.