• deter dangler
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
I am setting a Controller extension variable from VF page using apex action Function in the call back of the remote action method and then trying to read this value from another method in the controller extension.

Here is the code:

Controller Extension:
 
global with sharing class MyController {
    public String variableOne{get;set;}

    public MyController(ApexPages.StandardController stdController) {
    }

    public PageReference methodTwo() {
        System.debug('Variable value from methodTwo is '+ variableOne); 
        return null;
    }

    public PageReference methodThree() {
        System.debug('variable value from methodThree is '+ variableOne);
        return null;
    }

    @RemoteAction
    global static String methodOne(String s1){
        return s1+'123';
    }

}

My VisualForce Page:
 
<apex:page standardController="Account" extensions="MyController">
<c:ScriptsComponent id="scmp"/>
<script type="text/javascript">
    var records;
    function functionOne(){
        console.log('Entered the functionOne method');
        Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyController.methodOne}',
        'Andrew',
        function(result,event){
            console.log('result->' + JSON.stringify(result));
            records = result;
            if(event.status){
                console.log('result we got back from controller is '+records);
                setValueJS(records);
                methodOneJS();
            }
        });
    }
</script>

<div>
    <p onClick="functionOne(); return false;">Click Here</p>
    <apex:form >
        <apex:actionFunction name="setValueJS" action="{!methodTwo}">
            <apex:param name="parm1" assignTo="{!variableOne}" value=""></apex:param>
        </apex:actionFunction>
        <apex:actionFunction name="methodOneJS" action="{!methodThree}">
        </apex:actionFunction>
    </apex:form>
</div>
</apex:page>
  1. I never see the debug line in methodTwo priting.
  2. Debug line in methodThree always says that the variable value is null
  3. This might be javascript or jquery but the page reloads after i clicking on the p element
Anybody suggestions on what I am doing wrong?
I have a custom field "FieldOne" of type Rich Text Area on Custom Object and I am setting the value for this field in apex as below :
 
<p style="word-wrap:break-word;">aLongAnnoyingContinuousWordWithNoSpacesInBetweenThemIReallyWantToWrapThisUsingCSSWordWrapStylePropertyButItDoesnotWorkAndSimplyDisplaysAsOneContinuousLine</p>
But on the detail page of the Object, It just displays as a long continuous text and user has to scroll to the right to see the complete text.

When I inspected this element on the page using FireBug it shows that style attribute is empty for the <p> element..

Why is salesforce stripping the word-wrap property from the style attribute? or am I doing something wrong?
 
I am new to salesforce, so trying every example that is given there on the helo document.

The below code is from the link https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_qs_HelloWorld.htm|StartTopic=Content%2Fapex_qs_HelloWorld.htm|SkinName=webhelp
 
@isTest
private class MixedDML {
    static testMethod void mixedDMLExample() {  
        User u;
        Account a;
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
       // Insert account as current user
        System.runAs (thisUser) {
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
            UserRole r = [SELECT Id FROM UserRole WHERE Name='COO'];
            u = new User(alias = 'jsmith', email='jsmith@acme.com', 
                emailencodingkey='UTF-8', lastname='Smith', 
                languagelocalekey='en_US', 
                localesidkey='en_US', profileid = p.Id, userroleid = r.Id,
                timezonesidkey='America/Los_Angeles', 
                username='jsmith@acme.com');
            insert u;
            a = new Account(name='Acme');
            insert a;
        }
    }
}
As per the link, this code should throw error if i remove the block System.runAs() but it is working fine.

Am I doing something wrong??

I am just running my test class in mavensmate
 
I have the below code:
 
Set<String> fieldNames = schema.describeSObjects(new String[] {'User'})[0].fields.getMap().keyset();
List<String> iterableFields = new List<String>(fieldNames);
String query = 'SELECT '+ String.join(iterableFields,',')+ ' FROM User WHERE Id=:UserInfo.getUserId()';
User user = Database.query(query); //Line 10
When running the code, I am getting the below error:
  1. line 10, column 1
  2. System.QueryException: unexpected token: '('
Can somebody help what is the problem in this?
I am setting a Controller extension variable from VF page using apex action Function in the call back of the remote action method and then trying to read this value from another method in the controller extension.

Here is the code:

Controller Extension:
 
global with sharing class MyController {
    public String variableOne{get;set;}

    public MyController(ApexPages.StandardController stdController) {
    }

    public PageReference methodTwo() {
        System.debug('Variable value from methodTwo is '+ variableOne); 
        return null;
    }

    public PageReference methodThree() {
        System.debug('variable value from methodThree is '+ variableOne);
        return null;
    }

    @RemoteAction
    global static String methodOne(String s1){
        return s1+'123';
    }

}

My VisualForce Page:
 
<apex:page standardController="Account" extensions="MyController">
<c:ScriptsComponent id="scmp"/>
<script type="text/javascript">
    var records;
    function functionOne(){
        console.log('Entered the functionOne method');
        Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyController.methodOne}',
        'Andrew',
        function(result,event){
            console.log('result->' + JSON.stringify(result));
            records = result;
            if(event.status){
                console.log('result we got back from controller is '+records);
                setValueJS(records);
                methodOneJS();
            }
        });
    }
</script>

<div>
    <p onClick="functionOne(); return false;">Click Here</p>
    <apex:form >
        <apex:actionFunction name="setValueJS" action="{!methodTwo}">
            <apex:param name="parm1" assignTo="{!variableOne}" value=""></apex:param>
        </apex:actionFunction>
        <apex:actionFunction name="methodOneJS" action="{!methodThree}">
        </apex:actionFunction>
    </apex:form>
</div>
</apex:page>
  1. I never see the debug line in methodTwo priting.
  2. Debug line in methodThree always says that the variable value is null
  3. This might be javascript or jquery but the page reloads after i clicking on the p element
Anybody suggestions on what I am doing wrong?
I have the below code:
 
Set<String> fieldNames = schema.describeSObjects(new String[] {'User'})[0].fields.getMap().keyset();
List<String> iterableFields = new List<String>(fieldNames);
String query = 'SELECT '+ String.join(iterableFields,',')+ ' FROM User WHERE Id=:UserInfo.getUserId()';
User user = Database.query(query); //Line 10
When running the code, I am getting the below error:
  1. line 10, column 1
  2. System.QueryException: unexpected token: '('
Can somebody help what is the problem in this?