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
Akhil Katkam 5Akhil Katkam 5 

not knowing where is error whether apex or controller?

Hi Developer Community ,
I have been working on a task in my project , i will share the ocde of component , js and apex function .
My scenario is , i have a standard object :OPPORTUNITY and
Custom object: competition__c
in my opportunity there is a custom field called “Main_Competitor” (text field ) and in my competition there is a field called “Competitor” (look up field)

i have created a custom aura component and displayed in opportunity record page
User-added image
Competition.cmp:

<aura:component controller="oppcompquery" implements=" .......">
     <aura:attribute name="selectedId" type="String" />
         <aura:attribute name="competitionlist" type="String" />
<c:lookupField 
                    objectAPIName="Competition__c" 
                    label="PRIMARY COMPETITION"
                    returnFields="['Name']" 
                    queryFields="['Name']"
                    selectedId="{!v.selectedId}"
                    />
    <lightning:button label="set as primary" onclick="{!c.request1}" variant="brand" name="name2" class="slds-m-right_small"/>


controller.JS:

request1: function(component, event, helper) {
        var recId = component.get("v.selectedId");
        alert('hi');
        var action = component.get("c.fetchCompetitions");
        action.setParams({
            "recordId": component.get("v.recordId"),
            "recId": recId
        }); // Create a callback that is executed after 
        action.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") { // Alert the user with the value returned 
                    // from the server 
                    alert("From server: " + response.getReturnValue());
                    // You would typically fire a event here to trigger 
                    // client-side notification that the server-side 
                    // action is complete 
                } else if (state === "INCOMPLETE") {
                    // do something 
                } else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + errors[0].message);
                        }
                    } else {
                        console.log("Unknown error");
                    }
                }
            });
                $A.enqueueAction(action);
        }



apex class:

 @AuraEnabled
    public static void fetchCompetitions(String recordId, String recId){
                  System.debug('hi');
                   system.debug('recordId' +recordId);
                    system.debug('recId' +recId);
        List<Opportunity> opp=new List<Opportunity>();
        Opportunity o = [select id,Name,MainCompetitors__c from Opportunity where id=:recordId];
        List<Competitor__c> cmptList=[select id,Name  from Competitor__c where id=:recId];
        for(Competitor__c comp : cmptList){
           Opportunity opList = new Opportunity();    
           opList.MainCompetitors__c = comp.Name;        
            opp.add(opList);
        }
       update opp; 
        system.debug('opp' +opp);

    }

i am also getting a pop up : ((From server: null))
this error is getting after clicking on set as primary in pop up box 

please look into this code and help me where where is error

Thanks in Advance
ShivankurShivankur (Salesforce Developers) 
Hi Akhil,

Looking at the error, it seems somewhere in the code a null value is being passed or being received for assignment.

Please try to add more debug logs in your apex(to check values for variable assignments) and check if you are getting the values printed in debug as expected for your functionality. This way you would be able to fix the issue within the code implemented.

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.