1

I'm trying to follow the blog for SmsToLead here and I'm getting an error I don't understand

Error msg:

Cvc-elt.1: Cannot find the declaration of element 'html'.

This is my Visual Force code:

    <apex:page controller="SmsToLead">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Twilio SmsToLead</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->

</apex:page>

This is my Apex Class:

/* * SmsToLead.cls * * Shows how to receive SMS messages in Apex Code, creating Leads in a Campaign */

/* First, I define the class, with a @RestResource annotation. This is a RESTful web service that will be deployed at the relative URL /smstolead */ @RestResource(urlMapping='/smstolead') global class SmsToLead {

/* I’ve already installed the Twilio library and configured a custom setting with my Twilio account credentials, so I can get a reference to my Twilio account by just calling TwilioAPI.getDefaultAccount(): */ static TwilioAccount account = TwilioAPI.getDefaultAccount();

@future(callout=true)
public static void reply(String fromNumber, String toNumber, String message) {
    Map<String, String> params = new Map<String, String>{
      'From' => fromNumber, 
      'To' => toNumber, 
      'Body' => message
    };

    TwilioSms sms = account.getSmsMessages().create(params);
    System.debug('Sent SMS SID: '+sms.getSid());
}

/*

Now I define a method that will accept an HTTP POST from Twilio: */

@HttpPost
global static void incomingSMS() {
/*
I’ll be sending an email, so I reserve capacity up front to do so. This ensures that, if I’ve already reached my daily email limit,
 an error will be thrown before any more processing is done.
*/
    // This will error out with System.LimitException if we would exceed 
    // our daily email limit
    Messaging.reserveSingleEmailCapacity(1);

    String expectedSignature = 
        RestContext.request.headers.get('X-Twilio-Signature');
    String url = 'https://' + RestContext.request.headers.get('Host') + 
        '/services/apexrest' + RestContext.request.requestURI;
    Map <String, String> params = RestContext.request.params;

    // Validate signature
    if (!TwilioAPI.getDefaultClient().validateRequest(expectedSignature, url, params)) {
        RestContext.response.statusCode = 403;
        RestContext.response.responseBody = Blob.valueOf('Failure! Rcvd '+expectedSignature+'\nURL '+url/*+'\nHeaders'+RestContext.request.headers*/);
        return;
    }

    // Twilio likes to see something in the response body, otherwise it reports
    // a 502 error in https://www.twilio.com/user/account/log/notifications
    RestContext.response.responseBody = Blob.valueOf('ok');

    // Extract useful fields from the incoming SMS
    String leadNumber     = params.get('From');
    String campaignNumber = params.get('To');
    String leadEmail      = params.get('Body');

    // Try to find a matching Campaign
    Campaign campaign = null;
    try {
        campaign = [SELECT Id, Name, NumberSent FROM Campaign WHERE Phone__c = :campaignNumber LIMIT 1];
    } catch (QueryException qe) {
        reply(campaignNumber, leadNumber, 'No Campaign configured. Sorry.');
        return;
    }

    // Create and insert a new Lead
    Lead lead = new Lead(LastName = 'From SMS',
        Company = 'From SMS',
        Email = leadEmail, 
        Phone = leadNumber);

    try {
        insert lead;
    } catch (DmlException dmle) {
        String message = (dmle.getDmlType(0) == StatusCode.INVALID_EMAIL_ADDRESS)
            ? leadEmail+' doesn\'t look like an email address. Please try again.'
            : 'An error occurred. Sorry.';
        reply(campaignNumber, leadNumber, message);
        return;
    }

    // Link the Lead to the Campaign
    insert new CampaignMember(CampaignId = campaign.Id, LeadId = lead.Id);

    // We're done - send an SMS 
    reply(campaignNumber, leadNumber, 'Thanks for registering. We\'ll send you a confirmation email!');

    // Send an email, recording it as an activity
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setTargetObjectId(lead.Id);
    mail.setSaveAsActivity(true);
    mail.setSenderDisplayName(campaign.Name);
    mail.setSubject('Welcome!');
    mail.setPlainTextBody('Thanks for registering!');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

}

and my Twilio URL: https://domain name.force.com/smstolead

  • It seems that you have only updated Visualforce page code not apex class. are you trying to save VF code in Apex class ? – Deepak Kumar Shyoran Jan 26 '16 at 17:54
  • the tutorial that I was following actually did not even have a VF page in their instruction but I was looking at other examples that always had a VF controller directed to an Apex Class. I suspect that I don't really require a VF page as everything I need seems to be in the apex class. However when configuring the site the "Active Site Home " is a required field. therefore I added a basic VF and directed it to that controller. ultimately what I'm trying to do is receive an SMS , upset the lead and reply back to SMS – Robert Wynter Jan 26 '16 at 18:05
  • The code which you have mentioned under "This is my Apex Class" .. where are you trying to save it in Apex Class or in VisualForce page ? – Deepak Kumar Shyoran Jan 26 '16 at 18:32
  • OOPs my bad. I pasted the wrong code for my apex class. my apologies for the confusion. AND I'm not sure how to edit this page to add the right code – Robert Wynter Jan 26 '16 at 19:11
  • I've cut my apex class down to something simple. I believe the issue is not in my apex class but in my configuration as it does not matter how simple my class is I get the same error Cvc-elt.1: Cannot find the declaration of element 'html'. – Robert Wynter Jan 27 '16 at 18:12
1

I got your point what you have done has put some extra code before <apex:page> tag which is not allowed in VF page. As you cann't write anything before <apex:page> and after </apex:page> tag in salesforce VF pages.

This is your current code which you are trying to save,

<?xml version="1.0" encoding="UTF-8" ?><apex:page controller="SmsToLead" action="{!init}" showHeader="false" sidebar="false">
    <center> <apex:pageBlock title="Twilio Request Listener"></apex:pageBlock> </center>
    <Response> <Message>Thanks for the text</Message> </Response> 
</apex:page>

Simply replace your code with below code.

<apex:page controller="SmsToLead" action="{!init}" showHeader="false" sidebar="false">
        <center> <apex:pageBlock title="Twilio Request Listener"></apex:pageBlock> </center>
        <Response> <Message>Thanks for the text</Message> </Response> 
</apex:page>
|improve this answer|||||
  • Thanks for the update. Originaly I did not have the XML code there. I gave that a try after the Twilio support person replied back to my inquiry that my page needs to be in XML format in order for the reply. I've since then removed that first line and still no luck. I'm still getting the error: Warning 12200 Schema validation warning Description Cvc-elt.1: Cannot find the declaration of element 'html'. – Robert Wynter Jan 28 '16 at 14:29

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.