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
Johanna MattssonJohanna Mattsson 

Create the Visualforce Page unit error

I have a problem pasting the code from Step 4. From README.md, copy all of the code from <apex:page Controller="VisionController"> to </apex:page> and paste it in the Visualforce Markup tab.

Error: Unknown property 'VisionController.callVisionUrl'Create Apex property 'VisionController.callVisionUrl'
Create Apex method 'VisionController.getCallVisionUrl'

I have seen a few replies on here from earlier but none of the solutions work, greatful for the help I can get

My code:

<apex:page Controller="VisionController">
  <apex:form >
  <apex:pageBlock >
      <apex:image url="https://einstein.ai/images/generalimage.jpg">
      </apex:image>
      <br/>
      <apex:repeat value="{!AccessToken}" var="accessToken">
          Access Token:<apex:outputText value="{!accessToken}" /><br/>
    </apex:repeat>
      <br/>
      <apex:repeat value="{!callVisionUrl}" var="prediction">
          <apex:outputText value="{!prediction.label}" />:<apex:outputText value="{!prediction.probability}" /><br/>
      </apex:repeat>
  </apex:pageBlock>
<!--  <apex:pageBlock > -->
<!--      <apex:repeat value="{!callVisionContent}" var="prediction"> -->
<!--          <apex:outputText value="{!prediction.label}" />:<apex:outputText value="{!prediction.probability}" /><br/> -->
<!--    </apex:repeat> -->
<!--  </apex:pageBlock> -->
  </apex:form>

</apex:page>
Raj VakatiRaj Vakati
Try this code


Page 

 
<apex:page Controller="VisionController">
  <apex:slds />
  <div styleClass="slds-scope">
    <apex:form >
      <apex:pageBlock >
        <apex:pageBlockSection>
          <apex:pageBlockSectionItem>
            <apex:image width="300" url="{!imageUrl}"></apex:image>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem>
            <apex:inputText style="width: 100%" value="{!imageUrl}" />
          </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <apex:pageBlockButtons>
          <apex:commandButton action="{!predict}" value="Predict" />
        </apex:pageBlockButtons>
      </apex:pageBlock>
      <apex:pageBlock title="Results">
        <apex:dataTable value="{!predictions}" var="prediction" id="prediction-table">
          <apex:column>
            <apex:facet name="header">Label</apex:facet>
            <apex:outputText value="{!prediction.label}" />
          </apex:column>
          <apex:column>
            <apex:facet name="header">Probability</apex:facet>
            <apex:outputText value="{!prediction.probability}" />
          </apex:column>
        </apex:dataTable>
      </apex:pageBlock>
    </apex:form>
  </div>
</apex:page>
Controller
 
public class VisionController {
    // You can upload the `einstein_platform.pem` into your Salesforce org as `File` sObject and read it as below

    public String accessToken { get; set; }
    public String imageUrl { get; set; }
    public List<Vision.Prediction>  predictions { get; set; }

    public VisionController() {
      this.imageUrl = 'http://metamind.io/images/generalimage.jpg';
      this.accessToken = getAccessToken();
      this.predict();
    }

    private String getAccessToken() {
      // Ignore the File upload part and "jwt.pkcs" if you used a Salesforce certificate to sign up 
      // for an Einstein Platform account
      ContentVersion base64Content = [SELECT Title, VersionData FROM ContentVersion where Title='einstein_platform' OR  Title='predictive_services' ORDER BY Title LIMIT 1];
      String keyContents = base64Content.VersionData.tostring();
      keyContents = keyContents.replace('-----BEGIN RSA PRIVATE KEY-----', '');
      keyContents = keyContents.replace('-----END RSA PRIVATE KEY-----', '');
      keyContents = keyContents.replace('\n', '');

      // Get a new token
      JWT jwt = new JWT('RS256');
      // jwt.cert = 'JWTCert'; // Uncomment this if you used a Salesforce certificate to sign up for an Einstein Platform account
      jwt.pkcs8 = keyContents; // Comment this if you are using jwt.cert
      jwt.iss = 'developer.force.com';
      jwt.sub = 'kevinohara80@gmail.com';
      jwt.aud = 'https://api.metamind.io/v1/oauth2/token';
      jwt.exp = '3600';
      String access_token = JWTBearerFlow.getAccessToken('https://api.metamind.io/v1/oauth2/token', jwt);
      return access_token;
    }

    public void predict() {
      this.predictions =  Vision.predictUrl(this.imageUrl, this.accessToken, 'GeneralImageClassifier');
    }

}


 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Johanna,

Greetings to you!

Raj already replied to this post that's why I deleted my reply. So, here it is again:

Please try below code:
 
<apex:page Controller="VisionController">
  <apex:form >
  <apex:pageBlock >
      <apex:image url="https://einstein.ai/static/images/icons/einstein-glyph-blue.png">
      </apex:image>
      <br/>
      <apex:repeat value="{!AccessToken}" var="accessToken">
          Access Token:<apex:outputText value="{!accessToken}" /><br/>
    </apex:repeat>
      <br/>
      <apex:repeat value="{!callVisionUrl}" var="prediction">
          <apex:outputText value="{!prediction.label}" />:<apex:outputText value="{!prediction.probability}" /><br/>
      </apex:repeat>
  </apex:pageBlock>
<!--  <apex:pageBlock > -->
<!--      <apex:repeat value="{!callVisionContent}" var="prediction"> -->
<!--          <apex:outputText value="{!prediction.label}" />:<apex:outputText value="{!prediction.probability}" /><br/> -->
<!--    </apex:repeat> -->
<!--  </apex:pageBlock> -->
  </apex:form>
</apex:page>

Please check Apex Class code also:
 
public class VisionController {
    // You can upload the `einstein_platform.pem` into your Salesforce org as `File` sObject and read it as below
    public String getAccessToken() {
        // Ignore the File upload part and "jwt.pkcs" if you used a Salesforce certificate to sign up 
        // for an Einstein Platform account
        ContentVersion base64Content = [SELECT Title, VersionData FROM ContentVersion where Title='einstein_platform' OR  Title='predictive_services' ORDER BY Title LIMIT 1];
        String keyContents = base64Content.VersionData.tostring();
        keyContents = keyContents.replace('-----BEGIN RSA PRIVATE KEY-----', '');
        keyContents = keyContents.replace('-----END RSA PRIVATE KEY-----', '');
        keyContents = keyContents.replace('\n', '');
        
        // Get a new token
        JWT jwt = new JWT('RS256');
        // jwt.cert = 'JWTCert'; // Uncomment this if you used a Salesforce certificate to sign up for an Einstein Platform account
        jwt.pkcs8 = keyContents; // Comment this if you are using jwt.cert
        jwt.iss = 'developer.force.com';
        jwt.sub = 'rajamohanvakati@outlook.com';
        jwt.aud = 'https://api.metamind.io/v1/oauth2/token';
        jwt.exp = '3600';
        String access_token = JWTBearerFlow.getAccessToken('https://api.metamind.io/v1/oauth2/token', jwt);
        return access_token;    
    }
    
    public List<Vision.Prediction> getCallVisionUrl() {
        // Get a new token
        String access_token = getAccessToken();
        
        // Make a prediction using URL to a file
        return Vision.predictUrl('http://i.dailymail.co.uk/i/pix/2017/01/16/20/3C2EF44900000578-4125738-The_first_set_images_reveal_how_the_urban_expansion_in_New_Delhi-a-118_1484599843609.jpg',access_token,'GeneralImageClassifier');
    }
    
    public List<Vision.Prediction> getCallVisionContent() {
        // Get a new token
        String access_token = getAccessToken();
        
        // Make a prediction for an image stored in Salesforce
        // by passing the file as blob which is then converted to base64 string
        ContentVersion content = [SELECT Title,VersionData FROM ContentVersion where Id = '06841000000LkfCAAS' LIMIT 1];
        return Vision.predictBlob(content.VersionData, access_token, 'GeneralImageClassifier');
    }
}

I’m glad I was able to help!​

Kindly close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas