0

I have a return message but it does not show. Is there anything that I miss?

global with sharing class RM_convertProject {
        webservice static String OppId(String oID) {

           List<Opportunity2__c> getOpp = [SELECT Id, Name, Kick_off__c,StageName__c, Go_Live_Date__c FROM Opportunity2__c WHERE Id =: oId];
           List<Project__c> getProj = [SELECT Id,Opportunity__c FROM Project__c WHERE Opportunity__c =: oId];
           List<Project__c> getProjList = new List<Project__c>();
           String respond;

            for(Opportunity2__c opp: getOpp ){


                if(getProj.size() < 1){
                    //system.assertEquals('','' +getProj);
                    if(opp.StageName__c == 'Closed Won'){
                        CreateProject(opp);
                        return respond; 
                      }
                    else{
                        respond = 'You can only convert Closed Won Opportunities';
                        return respond;
                    }
                }
                else{
                    respond = 'You may only have 1 project per Opportunity';
                    return respond;
                }
            }
            return respond;   
        }
        Private static void CreateProject(Opportunity2__c opptyList){ 
            List<Project__c> newProject = new List<Project__c>();
            Date kickOffDate, goLiveDate;
            String OppName, respond;

            OppName = opptyList.Name;
            kickOffDate = opptyList.Kick_off__c;
            goLiveDate = opptyList.Go_Live_Date__c;

            Project__c newProj = new Project__c(
            Name = OppName +' - GDC Project ',
            kick_off_date__c = kickOffDate,
            Opportunity__c = opptyList.id,
            go_live_date__c = goLiveDate);
            newProject.add(newProj);

            if(newProject.size()>0){
               insert newProject;
               respond = 'Successfully created a new Project'; 
               CreateProjAssign(opptyList,newProject );
            } 
        }
        Private static void CreateProjAssign(Opportunity2__c opptyList,List<Project__c> newProject ){
            List<Project__c> updateprj = new List<Project__c>();
            List<Project_Assignment__c> newProjA = new List<Project_Assignment__c>();
            List<Project_Resource_Request__c> updateprr = new List<Project_Resource_Request__c>();
            List<Individual_Resource_Request__c> newIrr = new List<Individual_Resource_Request__c>();
            Integer a = 0;
            Id getProj;
            //List<Individual_Resource_Request__c> updateIrr = new List<Individual_Resource_Request__c>();
            List <Project_Resource_Request__c> prrList = [SELECT Id,Cancellation_Date__c, Original_Opportunity_Stage__c, Reason_for_Cancellation__c,
                                                            Resource_Request_Status__c, Opportunity__c FROM Project_Resource_Request__c WHERE Opportunity__c =: opptyList.Id];
            List <Individual_Resource_Request__c> irrList = [SELECT Id, Project_Resource_Request__c,Assigned_Resource_Contact__c, Assignment_Status__c,Preferred_End_Date__c, FTE__c,
                                                            Preferred_Resource__c,Role_picklist__c,Seniority_Level__c, Preferred_Start_Date__c, start_date_storage__c
                                                            FROM Individual_Resource_Request__c WHERE Project_Resource_Request__c =: prrList];  

            for(Project__c getProject : newProject){
                getProj = getProject.id;

            }
            for(Individual_Resource_Request__c irr: irrList){
                if(irr.Assigned_Resource_Contact__c != NULL){
                    irr.Assignment_Status__c = 'Active';
                }
                else{
                    a = a + 1;
                }
                Project_Assignment__c newPA = new Project_Assignment__c();
                    newPA.Project__c =getProj;
                    newPA.Role__c = irr.Role_picklist__c;
                    newPA.Assigned_Resource__c = irr.Assigned_Resource_Contact__c;
                    newPA.Seniority_Level__c = irr.Seniority_Level__c;
                    newPA.FTE__c = irr.FTE__c;
                    newPA.Start_Date__c = irr.Preferred_Start_Date__c;
                    newPA.End_Date__c = irr.Preferred_End_Date__c;
                    newPA.Assignment_Status__c = irr.Assignment_Status__c;

                newProjA.add(newPA);
                newIrr.add(irr);
            }
//============= UPDATE PRR ===================//
            for(Project_Resource_Request__c chkprr : prrList){
                if(a > 0){
                    chkprr.Resource_Request_Status__c = 'Partially Staffed';

                }
                else{
                    chkprr.Resource_Request_Status__c = 'Fully Staffed';
                }
                updateprr.add(chkprr);

            }

//============= UPDATE PROJECT ===================//
            for(Project__c chkprj : newProject){
                if(a > 0){
                    chkprj.Assignment_Status__c = 'Partially Staffed';

                }
                else{
                    chkprj.Assignment_Status__c = 'Fully Staffed';
                }
                updateprj.add(chkprj);
            }

//============= DML  ===================//          

            if(newProjA.size()>0){
               insert newProjA;
            }
            if(newIrr.size()>0){
              update newIrr;
            }
            if(updateprr.size()>0){
              update updateprr;
            }
            if(updateprj.size()>0){
              update updateprj;
            }     
        }

 } 

This is my button

if(confirm("Once you proceed, a new  Project will be created. Continue?")){
var resultMsg = sforce.apex.execute("RM_convertProject","OppId", 
{oID:"{!Opportunity2__c.Id}"});
}

if( resultMsg != null) { 
    alert(resultMsg ); 
}

This is the only line where the respond is not showing.

if(newProject.size()>0){
               insert newProject;
               respond = 'Successfully created a new Project'; 
               CreateProjAssign(opptyList,newProject );
            } 
3
  • Edit you question and specify the relevant section of code where is failing. You could proceed with proper debugging. Otherwise it is unclear what you are asking Commented Jan 16, 2018 at 7:15
  • Did you try to remove if condition on button code and then check. Might changes that you are actually getting null. Commented Jan 16, 2018 at 7:18
  • Hi Tushar, kindly view my edited. tried removing if in button but the result is same
    – begginers
    Commented Jan 16, 2018 at 7:25

1 Answer 1

2

Make respond a public static variable of the class; since it's function-local, the value in CreateProject isn't being returned to the other method. Alternately, return the value of respond from the CreateProject method back to the webservice function and assign it to the response variable.

4
  • how can I pass respond value from createProj to webservice? is it like this? OppId(NULL, respond);
    – begginers
    Commented Jan 16, 2018 at 7:46
  • 1
    @begginers Private static string CreateProject(Opportunity2__c opptyList){ ... return response;
    – sfdcfox
    Commented Jan 16, 2018 at 7:56
  • but Im passing 2.. Private static string CreateProject(Opportunity2__c opptyList, List<Project__c> newProject ){
    – begginers
    Commented Jan 17, 2018 at 6:49
  • @begginers That's not what your question shows. If you have a need to return multiple values, you might need a list or a custom object/class. My point was that your code is not returning the response back to the calling method.
    – sfdcfox
    Commented Jan 17, 2018 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .