2

I'm trying to create a visual force page with a table and a "request" button that will take the selected row and append it as a task.

Here's a photo of the table:

enter image description here

When a user hits request, I want to create a task that includes the deal name and deal owner.

Here is the VF page:

<apex:page controller="A7_OppsCntrl" standardStylesheets="false" sidebar="false">   

    <apex:form>
        <table id= 'a7Table' class='display'>
            <thead>
                <tr>
                    <th>Deal Name</th>
                    <th>Deal Owner</th>
                    <th>Request</th>
                </tr>
            </thead>
           <apex:repeat value="{!A7Opps}" var="row">
               <tr>
                   <apex:repeat value="{!A7Opps[row]}" var="cell">
                       <td> {!cell} </td>
                   </apex:repeat>
                   <td>
                       <apex:commandButton action="{!send2Admin}" value="Request" title="Send Request to Admin" oncomplete="" reRender="block">
                           <apex:param value="{!A7Opps[row]}" assignTo="{!paramValue}"/>
                       </apex:commandButton>
                   </td>
               </tr>
           </apex:repeat>
         </table>
    </apex:form>
</apex:page>

Here is the controller:

Global With Sharing class A7_OppsCntrl {

    string paramValue;

public void setParamValue(string paramValue){
        this.paramValue = paramValue;
    }

    public void send2Admin(){

        user adminId = [SELECT id from user where name like 'Sir Admin' limit 1];
        string userId = toolbox.grabUserId(); //Grabs context user ID
        user userName = [SELECT name from user where id = :userId];

        task leadReq = new task();
        leadReq.OwnerId = adminId.id;
        leadReq.Subject = 'New Request';
        leadReq.Description = userName.name+' is requesting '+this.paramValue;
        insert(leadReq);
    }

The task is successfully inserted, but the paramValue comes up as null.

What am I doing incorrectly (probably a lot ;)? How can I get the row data to be appended to the description of the task?

I've tried following this https://developer.salesforce.com/forums/ForumsMain?id=906F000000095uXIAQ.

Didn't help me.

Thanks!

UPDATE: It might be helpful to see how the A7Opps mapping works:

public static Map<string, list<string>> getA7Opps(){

        List<List<String>> parsedCSV = new List<List<String>>();
        Map<string, list<string>> A7Opps = new Map<string, list<string>>();
        Map<string, list<string>> userA7Opps = new Map<string, list<string>>();

        String fileString = getCSVFromDocs('A7Opps');
        parsedCSV = toolbox.csv2List(fileString, '\\|');
        for (List<String> row : parsedCSV){
          A7Opps.put(row[0], row);
        }

        list<string> targetIDs = new list<string>();
        string userId = toolbox.grabUserId(); 
        targetIDs.add(userId);
        list<deal__c> dealOriginator = [SELECT name, Deal_number__c, owner.id, owner.name 
                                        FROM deal__c 
                                        WHERE owner.id in :targetIDs AND Deal_number__c in :A7Opps.keySet()];

        for(deal__c deal:dealOriginator){
            A7Opps.get(deal.Deal_Number__c).add(deal.name);
            A7Opps.get(deal.Deal_Number__c).add(deal.owner.name);
            userA7Opps.put(deal.Deal_Number__c, A7Opps.get(deal.Deal_Number__c));   
        }
        return userA7Opps;
    }

EDIT: I've updated the controller code to:

 public String paramValue {get; set;}

    public static void send2Admin(){

        user adminId = [SELECT id from user where name like 'Sir Admin' limit 1];
        string userId = toolbox.grabUserId();
        user userName = [SELECT name from user where id = :userId];

        task leadReq = new task();
        leadReq.OwnerId = adminId.id;
        leadReq.Subject = 'New Lead Request';
        leadReq.Description = userName.name+' is requesting '+ paramValue; //this doesn't work
        insert(leadReq);

    }

paramValue cannot be referenced in the method send2Admin(), the var doesn't exist...

1

Try changing

string paramValue;

to this

public String paramValue {get; set;}

and completely removing

public void setParamValue(string paramValue){
    this.paramValue = paramValue;
}

also add a "name" attribute to your tag like so

<apex:param name="whatever" value="{!a7Opps[row]}" assignTo="{!paramValue}" />
8
  • By switching, I now can't access paramValue from the send2Admin method. I thought something like this.paramValue might work, but nope.
    – ZAR
    Apr 23 '15 at 18:26
  • @ZAR Can you show the code for the A7Opps map, with the Keys and Values as well?
    – dBeltowski
    Apr 23 '15 at 18:31
  • It's just a bunch of lists of string parsed from a CSV.
    – ZAR
    Apr 23 '15 at 18:36
  • @ZAR Check out my updated post. It looks like you need to specify the individual strings, rather than pass a the list of strings.
    – dBeltowski
    Apr 23 '15 at 18:43
  • 1
    @ZAR Add a "name" attribute to the param tag. I've updated my answer again. You're right that the row[0] won't work, I was being stupid in saying that. As for the public String paramValue {get; set;} is just a short form setter method for the paramValue.
    – dBeltowski
    Apr 23 '15 at 19:16
0

two tips:

1.- Change "A7Opps[row]" for "row"

2.- static string paramValue;

let me know if it works.

5
  • Changed to static - got this error: Class static variable cannot be accessed via object instance
    – ZAR
    Apr 23 '15 at 16:16
  • Change the method to static too: public static void send2Admin(){
    – Asiereiki
    Apr 23 '15 at 16:19
  • If method is static, it cannot access paramValue - I get this error: "Variable does not exist: this.paramValue"
    – ZAR
    Apr 23 '15 at 16:23
  • Of course. You need to erase "this." You cannot acces "this" because is static and there is no object instance.
    – Asiereiki
    Apr 23 '15 at 16:42
  • So no error but paramValue is again showing "null". Back to the original problem
    – ZAR
    Apr 23 '15 at 16:53
0

Have u gone throught this link???

enter link description here

Here JEFF DOUGLAS describe in a fantastic manner..

cherrs!

3
  • 1
    Can't see link - just see "enter link description"
    – ZAR
    Apr 23 '15 at 16:10
  • Now check bro i edited my post
    – Tinku
    Apr 23 '15 at 16:50
  • First suggestion on the page doesn't work in SF.
    – ZAR
    Apr 23 '15 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.